OLD | NEW |
1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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/nexe_load_manager.h" | 5 #include "components/nacl/renderer/nexe_load_manager.h" |
6 | 6 |
7 #include "base/command_line.h" | 7 #include "base/command_line.h" |
8 #include "base/logging.h" | 8 #include "base/logging.h" |
9 #include "base/metrics/histogram.h" | 9 #include "base/metrics/histogram.h" |
10 #include "base/strings/string_tokenizer.h" | 10 #include "base/strings/string_tokenizer.h" |
11 #include "base/strings/string_util.h" | 11 #include "base/strings/string_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_types.h" | 13 #include "components/nacl/common/nacl_types.h" |
14 #include "components/nacl/renderer/histogram.h" | 14 #include "components/nacl/renderer/histogram.h" |
15 #include "components/nacl/renderer/manifest_service_channel.h" | 15 #include "components/nacl/renderer/manifest_service_channel.h" |
16 #include "components/nacl/renderer/pnacl_translation_resource_host.h" | 16 #include "components/nacl/renderer/pnacl_translation_resource_host.h" |
17 #include "components/nacl/renderer/progress_event.h" | |
18 #include "components/nacl/renderer/sandbox_arch.h" | 17 #include "components/nacl/renderer/sandbox_arch.h" |
19 #include "components/nacl/renderer/trusted_plugin_channel.h" | 18 #include "components/nacl/renderer/trusted_plugin_channel.h" |
20 #include "content/public/common/content_client.h" | 19 #include "content/public/common/content_client.h" |
21 #include "content/public/common/content_switches.h" | 20 #include "content/public/common/content_switches.h" |
22 #include "content/public/common/sandbox_init.h" | 21 #include "content/public/common/sandbox_init.h" |
23 #include "content/public/renderer/pepper_plugin_instance.h" | 22 #include "content/public/renderer/pepper_plugin_instance.h" |
24 #include "content/public/renderer/render_thread.h" | 23 #include "content/public/renderer/render_thread.h" |
25 #include "content/public/renderer/render_view.h" | 24 #include "content/public/renderer/render_view.h" |
26 #include "content/public/renderer/renderer_ppapi_host.h" | 25 #include "content/public/renderer/renderer_ppapi_host.h" |
27 #include "ppapi/c/pp_bool.h" | 26 #include "ppapi/c/pp_bool.h" |
28 #include "ppapi/c/private/pp_file_handle.h" | 27 #include "ppapi/c/private/pp_file_handle.h" |
29 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" | 28 #include "ppapi/native_client/src/trusted/plugin/nacl_entry_points.h" |
30 #include "ppapi/shared_impl/ppapi_globals.h" | 29 #include "ppapi/shared_impl/ppapi_globals.h" |
31 #include "ppapi/shared_impl/ppapi_permissions.h" | 30 #include "ppapi/shared_impl/ppapi_permissions.h" |
32 #include "ppapi/shared_impl/ppapi_preferences.h" | 31 #include "ppapi/shared_impl/ppapi_preferences.h" |
33 #include "ppapi/shared_impl/scoped_pp_var.h" | 32 #include "ppapi/shared_impl/scoped_pp_var.h" |
34 #include "ppapi/shared_impl/var.h" | 33 #include "ppapi/shared_impl/var.h" |
35 #include "ppapi/shared_impl/var_tracker.h" | 34 #include "ppapi/shared_impl/var_tracker.h" |
36 #include "ppapi/thunk/enter.h" | 35 #include "ppapi/thunk/enter.h" |
| 36 #include "third_party/WebKit/public/web/WebDOMResourceProgressEvent.h" |
37 #include "third_party/WebKit/public/web/WebDocument.h" | 37 #include "third_party/WebKit/public/web/WebDocument.h" |
38 #include "third_party/WebKit/public/web/WebElement.h" | 38 #include "third_party/WebKit/public/web/WebElement.h" |
| 39 #include "third_party/WebKit/public/web/WebLocalFrame.h" |
39 #include "third_party/WebKit/public/web/WebPluginContainer.h" | 40 #include "third_party/WebKit/public/web/WebPluginContainer.h" |
40 #include "third_party/WebKit/public/web/WebView.h" | 41 #include "third_party/WebKit/public/web/WebView.h" |
41 #include "v8/include/v8.h" | 42 #include "v8/include/v8.h" |
42 | 43 |
43 namespace { | 44 namespace { |
44 | 45 |
45 const char* const kTypeAttribute = "type"; | 46 const char* const kTypeAttribute = "type"; |
46 // The "src" attribute of the <embed> tag. The value is expected to be either | 47 // The "src" attribute of the <embed> tag. The value is expected to be either |
47 // a URL or URI pointing to the manifest file (which is expected to contain | 48 // a URL or URI pointing to the manifest file (which is expected to contain |
48 // JSON matching ISAs with .nexe URLs). | 49 // JSON matching ISAs with .nexe URLs). |
49 const char* const kSrcManifestAttribute = "src"; | 50 const char* const kSrcManifestAttribute = "src"; |
50 // The "nacl" attribute of the <embed> tag. We use the value of this attribute | 51 // The "nacl" attribute of the <embed> tag. We use the value of this attribute |
51 // to find the manifest file when NaCl is registered as a plug-in for another | 52 // to find the manifest file when NaCl is registered as a plug-in for another |
52 // MIME type because the "src" attribute is used to supply us with the resource | 53 // MIME type because the "src" attribute is used to supply us with the resource |
53 // of that MIME type that we're supposed to display. | 54 // of that MIME type that we're supposed to display. |
54 const char* const kNaClManifestAttribute = "nacl"; | 55 const char* const kNaClManifestAttribute = "nacl"; |
55 // Define an argument name to enable 'dev' interfaces. To make sure it doesn't | 56 // Define an argument name to enable 'dev' interfaces. To make sure it doesn't |
56 // collide with any user-defined HTML attribute, make the first character '@'. | 57 // collide with any user-defined HTML attribute, make the first character '@'. |
57 const char* const kDevAttribute = "@dev"; | 58 const char* const kDevAttribute = "@dev"; |
58 | 59 |
59 const char* const kNaClMIMEType = "application/x-nacl"; | 60 const char* const kNaClMIMEType = "application/x-nacl"; |
60 const char* const kPNaClMIMEType = "application/x-pnacl"; | 61 const char* const kPNaClMIMEType = "application/x-pnacl"; |
61 | 62 |
| 63 blink::WebString EventTypeToString(PP_NaClEventType event_type) { |
| 64 switch (event_type) { |
| 65 case PP_NACL_EVENT_LOADSTART: |
| 66 return blink::WebString::fromUTF8("loadstart"); |
| 67 case PP_NACL_EVENT_PROGRESS: |
| 68 return blink::WebString::fromUTF8("progress"); |
| 69 case PP_NACL_EVENT_ERROR: |
| 70 return blink::WebString::fromUTF8("error"); |
| 71 case PP_NACL_EVENT_ABORT: |
| 72 return blink::WebString::fromUTF8("abort"); |
| 73 case PP_NACL_EVENT_LOAD: |
| 74 return blink::WebString::fromUTF8("load"); |
| 75 case PP_NACL_EVENT_LOADEND: |
| 76 return blink::WebString::fromUTF8("loadend"); |
| 77 case PP_NACL_EVENT_CRASH: |
| 78 return blink::WebString::fromUTF8("crash"); |
| 79 } |
| 80 NOTIMPLEMENTED(); |
| 81 return blink::WebString(); |
| 82 } |
| 83 |
62 static int GetRoutingID(PP_Instance instance) { | 84 static int GetRoutingID(PP_Instance instance) { |
63 // Check that we are on the main renderer thread. | 85 // Check that we are on the main renderer thread. |
64 DCHECK(content::RenderThread::Get()); | 86 DCHECK(content::RenderThread::Get()); |
65 content::RendererPpapiHost *host = | 87 content::RendererPpapiHost *host = |
66 content::RendererPpapiHost::GetForPPInstance(instance); | 88 content::RendererPpapiHost::GetForPPInstance(instance); |
67 if (!host) | 89 if (!host) |
68 return 0; | 90 return 0; |
69 return host->GetRoutingIDForWidget(instance); | 91 return host->GetRoutingIDForWidget(instance); |
70 } | 92 } |
71 | 93 |
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
139 // TODO(dmichael): Can we avoid stashing away so much state? | 161 // TODO(dmichael): Can we avoid stashing away so much state? |
140 nexe_size_ = nexe_bytes_read; | 162 nexe_size_ = nexe_bytes_read; |
141 HistogramSizeKB("NaCl.Perf.Size.Nexe", | 163 HistogramSizeKB("NaCl.Perf.Size.Nexe", |
142 static_cast<int32_t>(nexe_size_ / 1024)); | 164 static_cast<int32_t>(nexe_size_ / 1024)); |
143 HistogramStartupTimeMedium( | 165 HistogramStartupTimeMedium( |
144 "NaCl.Perf.StartupTime.NexeDownload", | 166 "NaCl.Perf.StartupTime.NexeDownload", |
145 base::TimeDelta::FromMilliseconds(time_since_open), | 167 base::TimeDelta::FromMilliseconds(time_since_open), |
146 nexe_size_); | 168 nexe_size_); |
147 | 169 |
148 // Inform JavaScript that we successfully downloaded the nacl module. | 170 // Inform JavaScript that we successfully downloaded the nacl module. |
149 ProgressEvent progress_event(PP_NACL_EVENT_PROGRESS, url, true, nexe_size_, | 171 ProgressEvent progress_event(pp_instance_, PP_NACL_EVENT_PROGRESS, url, |
150 nexe_size_); | 172 true, nexe_size_, nexe_size_); |
151 DispatchProgressEvent(pp_instance_, progress_event); | 173 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 174 FROM_HERE, |
| 175 base::Bind(&NexeLoadManager::DispatchEvent, |
| 176 weak_factory_.GetWeakPtr(), |
| 177 progress_event)); |
| 178 |
152 load_start_ = base::Time::Now(); | 179 load_start_ = base::Time::Now(); |
153 } | 180 } |
154 } | 181 } |
155 | 182 |
156 void NexeLoadManager::ReportLoadSuccess(const std::string& url, | 183 void NexeLoadManager::ReportLoadSuccess(const std::string& url, |
157 uint64_t loaded_bytes, | 184 uint64_t loaded_bytes, |
158 uint64_t total_bytes) { | 185 uint64_t total_bytes) { |
159 ready_time_ = base::Time::Now(); | 186 ready_time_ = base::Time::Now(); |
160 if (!IsPNaCl()) { | 187 if (!IsPNaCl()) { |
161 base::TimeDelta load_module_time = ready_time_ - load_start_; | 188 base::TimeDelta load_module_time = ready_time_ - load_start_; |
162 HistogramStartupTimeSmall( | 189 HistogramStartupTimeSmall( |
163 "NaCl.Perf.StartupTime.LoadModule", load_module_time, nexe_size_); | 190 "NaCl.Perf.StartupTime.LoadModule", load_module_time, nexe_size_); |
164 HistogramStartupTimeMedium( | 191 HistogramStartupTimeMedium( |
165 "NaCl.Perf.StartupTime.Total", ready_time_ - init_time_, nexe_size_); | 192 "NaCl.Perf.StartupTime.Total", ready_time_ - init_time_, nexe_size_); |
166 } | 193 } |
167 | 194 |
168 // Check that we are on the main renderer thread. | 195 // Check that we are on the main renderer thread. |
169 DCHECK(content::RenderThread::Get()); | 196 DCHECK(content::RenderThread::Get()); |
170 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); | 197 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); |
171 | 198 |
172 // Inform JavaScript that loading was successful and is complete. | 199 // Inform JavaScript that loading was successful and is complete. |
173 ProgressEvent load_event(PP_NACL_EVENT_LOAD, url, true, loaded_bytes, | 200 ProgressEvent load_event(pp_instance_, PP_NACL_EVENT_LOAD, url, true, |
174 total_bytes); | 201 loaded_bytes, total_bytes); |
175 DispatchProgressEvent(pp_instance_, load_event); | 202 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 203 FROM_HERE, |
| 204 base::Bind(&NexeLoadManager::DispatchEvent, |
| 205 weak_factory_.GetWeakPtr(), |
| 206 load_event)); |
176 | 207 |
177 ProgressEvent loadend_event(PP_NACL_EVENT_LOADEND, url, true, loaded_bytes, | 208 ProgressEvent loadend_event(pp_instance_, PP_NACL_EVENT_LOADEND, url, true, |
178 total_bytes); | 209 loaded_bytes, total_bytes); |
179 DispatchProgressEvent(pp_instance_, loadend_event); | 210 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 211 FROM_HERE, |
| 212 base::Bind(&NexeLoadManager::DispatchEvent, |
| 213 weak_factory_.GetWeakPtr(), |
| 214 loadend_event)); |
180 | 215 |
181 // UMA | 216 // UMA |
182 HistogramEnumerateLoadStatus(PP_NACL_ERROR_LOAD_SUCCESS, is_installed_); | 217 HistogramEnumerateLoadStatus(PP_NACL_ERROR_LOAD_SUCCESS, is_installed_); |
183 } | 218 } |
184 | 219 |
185 void NexeLoadManager::ReportLoadError(PP_NaClError error, | 220 void NexeLoadManager::ReportLoadError(PP_NaClError error, |
186 const std::string& error_message) { | 221 const std::string& error_message) { |
187 ReportLoadError(error, error_message, error_message); | 222 ReportLoadError(error, error_message, error_message); |
188 } | 223 } |
189 | 224 |
(...skipping 13 matching lines...) Expand all Loading... |
203 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); | 238 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); |
204 nexe_error_reported_ = true; | 239 nexe_error_reported_ = true; |
205 | 240 |
206 // We must set all properties before calling DispatchEvent so that when an | 241 // We must set all properties before calling DispatchEvent so that when an |
207 // event handler runs, the properties reflect the current load state. | 242 // event handler runs, the properties reflect the current load state. |
208 std::string error_string = std::string("NaCl module load failed: ") + | 243 std::string error_string = std::string("NaCl module load failed: ") + |
209 std::string(error_message); | 244 std::string(error_message); |
210 SetLastError(error_string); | 245 SetLastError(error_string); |
211 | 246 |
212 // Inform JavaScript that loading encountered an error and is complete. | 247 // Inform JavaScript that loading encountered an error and is complete. |
213 DispatchProgressEvent(pp_instance_, ProgressEvent(PP_NACL_EVENT_ERROR)); | 248 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
214 DispatchProgressEvent(pp_instance_, ProgressEvent(PP_NACL_EVENT_LOADEND)); | 249 FROM_HERE, |
| 250 base::Bind(&NexeLoadManager::DispatchEvent, |
| 251 weak_factory_.GetWeakPtr(), |
| 252 ProgressEvent(PP_NACL_EVENT_ERROR))); |
| 253 |
| 254 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 255 FROM_HERE, |
| 256 base::Bind(&NexeLoadManager::DispatchEvent, |
| 257 weak_factory_.GetWeakPtr(), |
| 258 ProgressEvent(PP_NACL_EVENT_LOADEND))); |
215 | 259 |
216 HistogramEnumerateLoadStatus(error, is_installed_); | 260 HistogramEnumerateLoadStatus(error, is_installed_); |
217 LogToConsole(console_message); | 261 LogToConsole(console_message); |
218 } | 262 } |
219 | 263 |
220 void NexeLoadManager::ReportLoadAbort() { | 264 void NexeLoadManager::ReportLoadAbort() { |
221 // Check that we are on the main renderer thread. | 265 // Check that we are on the main renderer thread. |
222 DCHECK(content::RenderThread::Get()); | 266 DCHECK(content::RenderThread::Get()); |
223 | 267 |
224 // Set the readyState attribute to indicate we need to start over. | 268 // Set the readyState attribute to indicate we need to start over. |
225 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); | 269 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); |
226 nexe_error_reported_ = true; | 270 nexe_error_reported_ = true; |
227 | 271 |
228 // Report an error in lastError and on the JavaScript console. | 272 // Report an error in lastError and on the JavaScript console. |
229 std::string error_string("NaCl module load failed: user aborted"); | 273 std::string error_string("NaCl module load failed: user aborted"); |
230 SetLastError(error_string); | 274 SetLastError(error_string); |
231 | 275 |
232 // Inform JavaScript that loading was aborted and is complete. | 276 // Inform JavaScript that loading was aborted and is complete. |
233 DispatchProgressEvent(pp_instance_, ProgressEvent(PP_NACL_EVENT_ABORT)); | 277 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
234 DispatchProgressEvent(pp_instance_, ProgressEvent(PP_NACL_EVENT_LOADEND)); | 278 FROM_HERE, |
| 279 base::Bind(&NexeLoadManager::DispatchEvent, |
| 280 weak_factory_.GetWeakPtr(), |
| 281 ProgressEvent(PP_NACL_EVENT_ABORT))); |
| 282 |
| 283 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 284 FROM_HERE, |
| 285 base::Bind(&NexeLoadManager::DispatchEvent, |
| 286 weak_factory_.GetWeakPtr(), |
| 287 ProgressEvent(PP_NACL_EVENT_LOADEND))); |
235 | 288 |
236 HistogramEnumerateLoadStatus(PP_NACL_ERROR_LOAD_ABORTED, is_installed_); | 289 HistogramEnumerateLoadStatus(PP_NACL_ERROR_LOAD_ABORTED, is_installed_); |
237 LogToConsole(error_string); | 290 LogToConsole(error_string); |
238 } | 291 } |
239 | 292 |
240 void NexeLoadManager::NexeDidCrash(const char* crash_log) { | 293 void NexeLoadManager::NexeDidCrash(const char* crash_log) { |
241 VLOG(1) << "Plugin::NexeDidCrash: crash event!"; | 294 VLOG(1) << "Plugin::NexeDidCrash: crash event!"; |
242 // The NaCl module voluntarily exited. However, this is still a | 295 // The NaCl module voluntarily exited. However, this is still a |
243 // crash from the point of view of Pepper, since PPAPI plugins are | 296 // crash from the point of view of Pepper, since PPAPI plugins are |
244 // event handlers and should never exit. | 297 // event handlers and should never exit. |
(...skipping 16 matching lines...) Expand all Loading... |
261 } | 314 } |
262 // In all cases, try to grab the crash log. The first error | 315 // In all cases, try to grab the crash log. The first error |
263 // reported may have come from the start_module RPC reply indicating | 316 // reported may have come from the start_module RPC reply indicating |
264 // a validation error or something similar, which wouldn't grab the | 317 // a validation error or something similar, which wouldn't grab the |
265 // crash log. In the event that this is called twice, the second | 318 // crash log. In the event that this is called twice, the second |
266 // invocation will just be a no-op, since the entire crash log will | 319 // invocation will just be a no-op, since the entire crash log will |
267 // have been received and we'll just get an EOF indication. | 320 // have been received and we'll just get an EOF indication. |
268 CopyCrashLogToJsConsole(crash_log); | 321 CopyCrashLogToJsConsole(crash_log); |
269 } | 322 } |
270 | 323 |
| 324 void NexeLoadManager::DispatchEvent(const ProgressEvent &event) { |
| 325 blink::WebPluginContainer* container = plugin_instance_->GetContainer(); |
| 326 // It's possible that container() is NULL if the plugin has been removed from |
| 327 // the DOM (but the PluginInstance is not destroyed yet). |
| 328 if (!container) |
| 329 return; |
| 330 blink::WebLocalFrame* frame = container->element().document().frame(); |
| 331 if (!frame) |
| 332 return; |
| 333 v8::HandleScope handle_scope(plugin_instance_->GetIsolate()); |
| 334 v8::Local<v8::Context> context( |
| 335 plugin_instance_->GetIsolate()->GetCurrentContext()); |
| 336 if (context.IsEmpty()) { |
| 337 // If there's no JavaScript on the stack, we have to make a new Context. |
| 338 context = v8::Context::New(plugin_instance_->GetIsolate()); |
| 339 } |
| 340 v8::Context::Scope context_scope(context); |
| 341 |
| 342 if (!event.resource_url.empty()) { |
| 343 blink::WebString url_string = blink::WebString::fromUTF8( |
| 344 event.resource_url.data(), event.resource_url.size()); |
| 345 blink::WebDOMResourceProgressEvent blink_event( |
| 346 EventTypeToString(event.event_type), |
| 347 event.length_is_computable, |
| 348 event.loaded_bytes, |
| 349 event.total_bytes, |
| 350 url_string); |
| 351 container->element().dispatchEvent(blink_event); |
| 352 } else { |
| 353 blink::WebDOMProgressEvent blink_event(EventTypeToString(event.event_type), |
| 354 event.length_is_computable, |
| 355 event.loaded_bytes, |
| 356 event.total_bytes); |
| 357 container->element().dispatchEvent(blink_event); |
| 358 } |
| 359 } |
| 360 |
271 void NexeLoadManager::set_trusted_plugin_channel( | 361 void NexeLoadManager::set_trusted_plugin_channel( |
272 scoped_ptr<TrustedPluginChannel> channel) { | 362 scoped_ptr<TrustedPluginChannel> channel) { |
273 trusted_plugin_channel_ = channel.Pass(); | 363 trusted_plugin_channel_ = channel.Pass(); |
274 } | 364 } |
275 | 365 |
276 void NexeLoadManager::set_manifest_service_channel( | 366 void NexeLoadManager::set_manifest_service_channel( |
277 scoped_ptr<ManifestServiceChannel> channel) { | 367 scoped_ptr<ManifestServiceChannel> channel) { |
278 manifest_service_channel_ = channel.Pass(); | 368 manifest_service_channel_ = channel.Pass(); |
279 } | 369 } |
280 | 370 |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
341 bool* is_data_uri) { | 431 bool* is_data_uri) { |
342 if (plugin_base_url_.is_valid()) { | 432 if (plugin_base_url_.is_valid()) { |
343 const GURL& resolved_url = plugin_base_url_.Resolve(url); | 433 const GURL& resolved_url = plugin_base_url_.Resolve(url); |
344 if (resolved_url.is_valid()) { | 434 if (resolved_url.is_valid()) { |
345 manifest_base_url_ = resolved_url; | 435 manifest_base_url_ = resolved_url; |
346 is_installed_ = manifest_base_url_.SchemeIs("chrome-extension"); | 436 is_installed_ = manifest_base_url_.SchemeIs("chrome-extension"); |
347 *is_data_uri = manifest_base_url_.SchemeIs("data"); | 437 *is_data_uri = manifest_base_url_.SchemeIs("data"); |
348 HistogramEnumerateManifestIsDataURI(*is_data_uri); | 438 HistogramEnumerateManifestIsDataURI(*is_data_uri); |
349 | 439 |
350 set_nacl_ready_state(PP_NACL_READY_STATE_OPENED); | 440 set_nacl_ready_state(PP_NACL_READY_STATE_OPENED); |
351 DispatchProgressEvent(pp_instance_, | 441 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
352 ProgressEvent(PP_NACL_EVENT_LOADSTART)); | 442 FROM_HERE, |
| 443 base::Bind(&NexeLoadManager::DispatchEvent, |
| 444 weak_factory_.GetWeakPtr(), |
| 445 ProgressEvent(PP_NACL_EVENT_LOADSTART))); |
353 return true; | 446 return true; |
354 } | 447 } |
355 } | 448 } |
356 ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, | 449 ReportLoadError(PP_NACL_ERROR_MANIFEST_RESOLVE_URL, |
357 std::string("could not resolve URL \"") + url + | 450 std::string("could not resolve URL \"") + url + |
358 "\" relative to \"" + | 451 "\" relative to \"" + |
359 plugin_base_url_.possibly_invalid_spec() + "\"."); | 452 plugin_base_url_.possibly_invalid_spec() + "\"."); |
360 return false; | 453 return false; |
361 } | 454 } |
362 | 455 |
363 void NexeLoadManager::ProcessNaClManifest(const std::string& program_url) { | 456 void NexeLoadManager::ProcessNaClManifest(const std::string& program_url) { |
364 GURL gurl(program_url); | 457 GURL gurl(program_url); |
365 DCHECK(gurl.is_valid()); | 458 DCHECK(gurl.is_valid()); |
366 if (gurl.is_valid()) | 459 if (gurl.is_valid()) |
367 is_installed_ = gurl.SchemeIs("chrome-extension"); | 460 is_installed_ = gurl.SchemeIs("chrome-extension"); |
368 set_nacl_ready_state(PP_NACL_READY_STATE_LOADING); | 461 set_nacl_ready_state(PP_NACL_READY_STATE_LOADING); |
369 DispatchProgressEvent(pp_instance_, ProgressEvent(PP_NACL_EVENT_PROGRESS)); | 462 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 463 FROM_HERE, |
| 464 base::Bind(&NexeLoadManager::DispatchEvent, |
| 465 weak_factory_.GetWeakPtr(), |
| 466 ProgressEvent(PP_NACL_EVENT_PROGRESS))); |
370 } | 467 } |
371 | 468 |
372 std::string NexeLoadManager::GetManifestURLArgument() const { | 469 std::string NexeLoadManager::GetManifestURLArgument() const { |
373 std::string manifest_url; | 470 std::string manifest_url; |
374 | 471 |
375 // If the MIME type is foreign, then this NEXE is being used as a content | 472 // If the MIME type is foreign, then this NEXE is being used as a content |
376 // type handler rather than directly by an HTML document. | 473 // type handler rather than directly by an HTML document. |
377 bool nexe_is_content_handler = | 474 bool nexe_is_content_handler = |
378 !mime_type_.empty() && | 475 !mime_type_.empty() && |
379 mime_type_ != kNaClMIMEType && | 476 mime_type_ != kNaClMIMEType && |
(...skipping 30 matching lines...) Expand all Loading... |
410 !nexe_error_reported_) { | 507 !nexe_error_reported_) { |
411 // Crashes will be more likely near startup, so use a medium histogram | 508 // Crashes will be more likely near startup, so use a medium histogram |
412 // instead of a large one. | 509 // instead of a large one. |
413 base::TimeDelta uptime = base::Time::Now() - ready_time_; | 510 base::TimeDelta uptime = base::Time::Now() - ready_time_; |
414 HistogramTimeMedium("NaCl.ModuleUptime.Crash", uptime.InMilliseconds()); | 511 HistogramTimeMedium("NaCl.ModuleUptime.Crash", uptime.InMilliseconds()); |
415 | 512 |
416 std::string message("NaCl module crashed"); | 513 std::string message("NaCl module crashed"); |
417 SetLastError(message); | 514 SetLastError(message); |
418 LogToConsole(message); | 515 LogToConsole(message); |
419 | 516 |
420 DispatchProgressEvent(pp_instance_, ProgressEvent(PP_NACL_EVENT_CRASH)); | 517 ppapi::PpapiGlobals::Get()->GetMainThreadMessageLoop()->PostTask( |
| 518 FROM_HERE, |
| 519 base::Bind(&NexeLoadManager::DispatchEvent, |
| 520 weak_factory_.GetWeakPtr(), |
| 521 ProgressEvent(PP_NACL_EVENT_CRASH))); |
421 nexe_error_reported_ = true; | 522 nexe_error_reported_ = true; |
422 } | 523 } |
423 // else ReportLoadError() and ReportLoadAbort() will be used by loading code | 524 // else ReportLoadError() and ReportLoadAbort() will be used by loading code |
424 // to provide error handling. | 525 // to provide error handling. |
425 } | 526 } |
426 | 527 |
427 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { | 528 void NexeLoadManager::CopyCrashLogToJsConsole(const std::string& crash_log) { |
428 base::StringTokenizer t(crash_log, "\n"); | 529 base::StringTokenizer t(crash_log, "\n"); |
429 while (t.GetNext()) | 530 while (t.GetNext()) |
430 LogToConsole(t.token()); | 531 LogToConsole(t.token()); |
431 } | 532 } |
432 | 533 |
433 } // namespace nacl | 534 } // namespace nacl |
OLD | NEW |