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