| 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 "components/nacl/common/nacl_host_messages.h" | 10 #include "components/nacl/common/nacl_host_messages.h" |
| (...skipping 79 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 90 nacl_ready_state_(PP_NACL_READY_STATE_UNSENT), | 90 nacl_ready_state_(PP_NACL_READY_STATE_UNSENT), |
| 91 nexe_error_reported_(false), | 91 nexe_error_reported_(false), |
| 92 plugin_instance_(content::PepperPluginInstance::Get(pp_instance)), | 92 plugin_instance_(content::PepperPluginInstance::Get(pp_instance)), |
| 93 weak_factory_(this) { | 93 weak_factory_(this) { |
| 94 } | 94 } |
| 95 | 95 |
| 96 NexeLoadManager::~NexeLoadManager() { | 96 NexeLoadManager::~NexeLoadManager() { |
| 97 } | 97 } |
| 98 | 98 |
| 99 void NexeLoadManager::ReportLoadError(PP_NaClError error, | 99 void NexeLoadManager::ReportLoadError(PP_NaClError error, |
| 100 const std::string& error_message) { | 100 const std::string& error_message, |
| 101 const std::string& console_message) { |
| 101 // Check that we are on the main renderer thread. | 102 // Check that we are on the main renderer thread. |
| 102 DCHECK(content::RenderThread::Get()); | 103 DCHECK(content::RenderThread::Get()); |
| 103 | 104 |
| 104 if (error == PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH) { | 105 if (error == PP_NACL_ERROR_MANIFEST_PROGRAM_MISSING_ARCH) { |
| 105 // A special case: the manifest may otherwise be valid but is missing | 106 // A special case: the manifest may otherwise be valid but is missing |
| 106 // a program/file compatible with the user's sandbox. | 107 // a program/file compatible with the user's sandbox. |
| 107 IPC::Sender* sender = content::RenderThread::Get(); | 108 IPC::Sender* sender = content::RenderThread::Get(); |
| 108 sender->Send( | 109 sender->Send( |
| 109 new NaClHostMsg_MissingArchError(GetRoutingID(pp_instance_))); | 110 new NaClHostMsg_MissingArchError(GetRoutingID(pp_instance_))); |
| 110 } | 111 } |
| 111 // TODO(dmichael): Move the following actions here: | |
| 112 // - Print error message to JavaScript console. | |
| 113 | |
| 114 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); | 112 set_nacl_ready_state(PP_NACL_READY_STATE_DONE); |
| 115 nexe_error_reported_ = true; | 113 nexe_error_reported_ = true; |
| 116 | 114 |
| 117 // We must set all properties before calling DispatchEvent so that when an | 115 // We must set all properties before calling DispatchEvent so that when an |
| 118 // event handler runs, the properties reflect the current load state. | 116 // event handler runs, the properties reflect the current load state. |
| 119 std::string error_string = std::string("NaCl module load failed: ") + | 117 std::string error_string = std::string("NaCl module load failed: ") + |
| 120 std::string(error_message); | 118 std::string(error_message); |
| 121 plugin_instance_->SetEmbedProperty( | 119 plugin_instance_->SetEmbedProperty( |
| 122 ppapi::StringVar::StringToPPVar("lastError"), | 120 ppapi::StringVar::StringToPPVar("lastError"), |
| 123 ppapi::StringVar::StringToPPVar(error_string)); | 121 ppapi::StringVar::StringToPPVar(error_string)); |
| (...skipping 10 matching lines...) Expand all Loading... |
| 134 base::Bind(&NexeLoadManager::DispatchEvent, | 132 base::Bind(&NexeLoadManager::DispatchEvent, |
| 135 weak_factory_.GetWeakPtr(), | 133 weak_factory_.GetWeakPtr(), |
| 136 ProgressEvent(PP_NACL_EVENT_LOADEND))); | 134 ProgressEvent(PP_NACL_EVENT_LOADEND))); |
| 137 | 135 |
| 138 HistogramEnumerate("NaCl.LoadStatus.Plugin", error, | 136 HistogramEnumerate("NaCl.LoadStatus.Plugin", error, |
| 139 PP_NACL_ERROR_MAX); | 137 PP_NACL_ERROR_MAX); |
| 140 std::string uma_name = is_installed_ ? | 138 std::string uma_name = is_installed_ ? |
| 141 "NaCl.LoadStatus.Plugin.InstalledApp" : | 139 "NaCl.LoadStatus.Plugin.InstalledApp" : |
| 142 "NaCl.LoadStatus.Plugin.NotInstalledApp"; | 140 "NaCl.LoadStatus.Plugin.NotInstalledApp"; |
| 143 HistogramEnumerate(uma_name, error, PP_NACL_ERROR_MAX); | 141 HistogramEnumerate(uma_name, error, PP_NACL_ERROR_MAX); |
| 142 |
| 143 LogToConsole(console_message); |
| 144 } | 144 } |
| 145 | 145 |
| 146 void NexeLoadManager::DispatchEvent(const ProgressEvent &event) { | 146 void NexeLoadManager::DispatchEvent(const ProgressEvent &event) { |
| 147 blink::WebPluginContainer* container = plugin_instance_->GetContainer(); | 147 blink::WebPluginContainer* container = plugin_instance_->GetContainer(); |
| 148 // It's possible that container() is NULL if the plugin has been removed from | 148 // It's possible that container() is NULL if the plugin has been removed from |
| 149 // the DOM (but the PluginInstance is not destroyed yet). | 149 // the DOM (but the PluginInstance is not destroyed yet). |
| 150 if (!container) | 150 if (!container) |
| 151 return; | 151 return; |
| 152 blink::WebFrame* frame = container->element().document().frame(); | 152 blink::WebFrame* frame = container->element().document().frame(); |
| 153 if (!frame) | 153 if (!frame) |
| (...skipping 46 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 200 void NexeLoadManager::set_nacl_ready_state(PP_NaClReadyState ready_state) { | 200 void NexeLoadManager::set_nacl_ready_state(PP_NaClReadyState ready_state) { |
| 201 nacl_ready_state_ = ready_state; | 201 nacl_ready_state_ = ready_state; |
| 202 SetReadOnlyProperty(ppapi::StringVar::StringToPPVar("readyState"), | 202 SetReadOnlyProperty(ppapi::StringVar::StringToPPVar("readyState"), |
| 203 PP_MakeInt32(ready_state)); | 203 PP_MakeInt32(ready_state)); |
| 204 } | 204 } |
| 205 | 205 |
| 206 void NexeLoadManager::SetReadOnlyProperty(PP_Var key, PP_Var value) { | 206 void NexeLoadManager::SetReadOnlyProperty(PP_Var key, PP_Var value) { |
| 207 plugin_instance_->SetEmbedProperty(key, value); | 207 plugin_instance_->SetEmbedProperty(key, value); |
| 208 } | 208 } |
| 209 | 209 |
| 210 void NexeLoadManager::LogToConsole(const std::string& message) { |
| 211 ppapi::PpapiGlobals::Get()->LogWithSource( |
| 212 pp_instance_, PP_LOGLEVEL_LOG, std::string("NativeClient"), message); |
| 213 } |
| 214 |
| 210 } // namespace nacl | 215 } // namespace nacl |
| OLD | NEW |