| OLD | NEW |
| (Empty) |
| 1 // Copyright (c) 2013 The Chromium Authors. All rights reserved. | |
| 2 // Use of this source code is governed by a BSD-style license that can be | |
| 3 // found in the LICENSE file. | |
| 4 | |
| 5 #include "ui/chromeos/network/network_connect.h" | |
| 6 | |
| 7 #include "base/bind.h" | |
| 8 #include "base/memory/scoped_ptr.h" | |
| 9 #include "base/strings/string_util.h" | |
| 10 #include "base/strings/utf_string_conversions.h" | |
| 11 #include "base/values.h" | |
| 12 #include "chromeos/login/login_state.h" | |
| 13 #include "chromeos/network/device_state.h" | |
| 14 #include "chromeos/network/network_activation_handler.h" | |
| 15 #include "chromeos/network/network_configuration_handler.h" | |
| 16 #include "chromeos/network/network_connection_handler.h" | |
| 17 #include "chromeos/network/network_event_log.h" | |
| 18 #include "chromeos/network/network_handler_callbacks.h" | |
| 19 #include "chromeos/network/network_profile.h" | |
| 20 #include "chromeos/network/network_profile_handler.h" | |
| 21 #include "chromeos/network/network_state.h" | |
| 22 #include "chromeos/network/network_state_handler.h" | |
| 23 #include "grit/ui_chromeos_strings.h" | |
| 24 #include "third_party/cros_system_api/dbus/service_constants.h" | |
| 25 #include "ui/base/l10n/l10n_util.h" | |
| 26 #include "ui/base/resource/resource_bundle.h" | |
| 27 #include "ui/chromeos/network/network_state_notifier.h" | |
| 28 #include "ui/message_center/message_center.h" | |
| 29 #include "ui/message_center/notification.h" | |
| 30 | |
| 31 using chromeos::DeviceState; | |
| 32 using chromeos::NetworkConfigurationHandler; | |
| 33 using chromeos::NetworkConnectionHandler; | |
| 34 using chromeos::NetworkHandler; | |
| 35 using chromeos::NetworkProfile; | |
| 36 using chromeos::NetworkProfileHandler; | |
| 37 using chromeos::NetworkState; | |
| 38 using chromeos::NetworkStateHandler; | |
| 39 using chromeos::NetworkTypePattern; | |
| 40 | |
| 41 namespace ui { | |
| 42 | |
| 43 namespace { | |
| 44 | |
| 45 // Returns true for carriers that can be activated through Shill instead of | |
| 46 // through a WebUI dialog. | |
| 47 bool IsDirectActivatedCarrier(const std::string& carrier) { | |
| 48 if (carrier == shill::kCarrierSprint) | |
| 49 return true; | |
| 50 return false; | |
| 51 } | |
| 52 | |
| 53 const NetworkState* GetNetworkState(const std::string& service_path) { | |
| 54 return NetworkHandler::Get()->network_state_handler()->GetNetworkState( | |
| 55 service_path); | |
| 56 } | |
| 57 | |
| 58 class NetworkConnectImpl : public NetworkConnect { | |
| 59 public: | |
| 60 explicit NetworkConnectImpl(Delegate* delegate); | |
| 61 ~NetworkConnectImpl() override; | |
| 62 | |
| 63 // NetworkConnect | |
| 64 void ConnectToNetwork(const std::string& service_path) override; | |
| 65 void SetTechnologyEnabled(const chromeos::NetworkTypePattern& technology, | |
| 66 bool enabled_state) override; | |
| 67 void ActivateCellular(const std::string& service_path) override; | |
| 68 void ShowMobileSetup(const std::string& service_path) override; | |
| 69 void ConfigureNetworkAndConnect(const std::string& service_path, | |
| 70 const base::DictionaryValue& properties, | |
| 71 bool shared) override; | |
| 72 void CreateConfigurationAndConnect(base::DictionaryValue* properties, | |
| 73 bool shared) override; | |
| 74 void CreateConfiguration(base::DictionaryValue* properties, | |
| 75 bool shared) override; | |
| 76 base::string16 GetErrorString(const std::string& error, | |
| 77 const std::string& service_path) override; | |
| 78 void ShowNetworkSettings(const std::string& service_path) override; | |
| 79 | |
| 80 private: | |
| 81 void HandleUnconfiguredNetwork(const std::string& service_path); | |
| 82 void OnConnectFailed(const std::string& service_path, | |
| 83 const std::string& error_name, | |
| 84 scoped_ptr<base::DictionaryValue> error_data); | |
| 85 bool GetNetworkProfilePath(bool shared, std::string* profile_path); | |
| 86 void OnConnectSucceeded(const std::string& service_path); | |
| 87 void CallConnectToNetwork(const std::string& service_path, | |
| 88 bool check_error_state); | |
| 89 void OnActivateFailed(const std::string& service_path, | |
| 90 const std::string& error_name, | |
| 91 scoped_ptr<base::DictionaryValue> error_data); | |
| 92 void OnActivateSucceeded(const std::string& service_path); | |
| 93 void OnConfigureFailed(const std::string& error_name, | |
| 94 scoped_ptr<base::DictionaryValue> error_data); | |
| 95 void OnConfigureSucceeded(bool connect_on_configure, | |
| 96 const std::string& service_path); | |
| 97 void CallCreateConfiguration(base::DictionaryValue* properties, | |
| 98 bool shared, | |
| 99 bool connect_on_configure); | |
| 100 void SetPropertiesFailed(const std::string& desc, | |
| 101 const std::string& service_path, | |
| 102 const std::string& config_error_name, | |
| 103 scoped_ptr<base::DictionaryValue> error_data); | |
| 104 void SetPropertiesToClear(base::DictionaryValue* properties_to_set, | |
| 105 std::vector<std::string>* properties_to_clear); | |
| 106 void ClearPropertiesAndConnect( | |
| 107 const std::string& service_path, | |
| 108 const std::vector<std::string>& properties_to_clear); | |
| 109 void ConfigureSetProfileSucceeded( | |
| 110 const std::string& service_path, | |
| 111 scoped_ptr<base::DictionaryValue> properties_to_set); | |
| 112 | |
| 113 Delegate* delegate_; | |
| 114 scoped_ptr<NetworkStateNotifier> network_state_notifier_; | |
| 115 base::WeakPtrFactory<NetworkConnectImpl> weak_factory_; | |
| 116 | |
| 117 DISALLOW_COPY_AND_ASSIGN(NetworkConnectImpl); | |
| 118 }; | |
| 119 | |
| 120 NetworkConnectImpl::NetworkConnectImpl(Delegate* delegate) | |
| 121 : delegate_(delegate), weak_factory_(this) { | |
| 122 network_state_notifier_.reset(new NetworkStateNotifier(this)); | |
| 123 } | |
| 124 | |
| 125 NetworkConnectImpl::~NetworkConnectImpl() { | |
| 126 } | |
| 127 | |
| 128 void NetworkConnectImpl::HandleUnconfiguredNetwork( | |
| 129 const std::string& service_path) { | |
| 130 const NetworkState* network = GetNetworkState(service_path); | |
| 131 if (!network) { | |
| 132 NET_LOG_ERROR("Configuring unknown network", service_path); | |
| 133 return; | |
| 134 } | |
| 135 | |
| 136 if (network->type() == shill::kTypeWifi) { | |
| 137 // Only show the config view for secure networks, otherwise do nothing. | |
| 138 if (network->security() != shill::kSecurityNone) { | |
| 139 delegate_->ShowNetworkConfigure(service_path); | |
| 140 } | |
| 141 return; | |
| 142 } | |
| 143 | |
| 144 if (network->type() == shill::kTypeWimax || | |
| 145 network->type() == shill::kTypeVPN) { | |
| 146 delegate_->ShowNetworkConfigure(service_path); | |
| 147 return; | |
| 148 } | |
| 149 | |
| 150 if (network->type() == shill::kTypeCellular) { | |
| 151 if (network->RequiresActivation()) { | |
| 152 ActivateCellular(service_path); | |
| 153 return; | |
| 154 } | |
| 155 if (network->cellular_out_of_credits()) { | |
| 156 ShowMobileSetup(service_path); | |
| 157 return; | |
| 158 } | |
| 159 // No special configure or setup for |network|, show the settings UI. | |
| 160 if (chromeos::LoginState::Get()->IsUserLoggedIn()) { | |
| 161 delegate_->ShowNetworkSettings(service_path); | |
| 162 } | |
| 163 return; | |
| 164 } | |
| 165 NOTREACHED(); | |
| 166 } | |
| 167 | |
| 168 // If |shared| is true, sets |profile_path| to the shared profile path. | |
| 169 // Otherwise sets |profile_path| to the user profile path if authenticated and | |
| 170 // available. Returns 'false' if unable to set |profile_path|. | |
| 171 bool NetworkConnectImpl::GetNetworkProfilePath(bool shared, | |
| 172 std::string* profile_path) { | |
| 173 if (shared) { | |
| 174 *profile_path = NetworkProfileHandler::GetSharedProfilePath(); | |
| 175 return true; | |
| 176 } | |
| 177 | |
| 178 if (!chromeos::LoginState::Get()->UserHasNetworkProfile()) { | |
| 179 NET_LOG_ERROR("User profile specified before login", ""); | |
| 180 return false; | |
| 181 } | |
| 182 | |
| 183 const NetworkProfile* profile = | |
| 184 NetworkHandler::Get()->network_profile_handler()->GetDefaultUserProfile(); | |
| 185 if (!profile) { | |
| 186 NET_LOG_ERROR("No user profile for unshared network configuration", ""); | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 *profile_path = profile->path; | |
| 191 return true; | |
| 192 } | |
| 193 | |
| 194 void NetworkConnectImpl::OnConnectFailed( | |
| 195 const std::string& service_path, | |
| 196 const std::string& error_name, | |
| 197 scoped_ptr<base::DictionaryValue> error_data) { | |
| 198 NET_LOG_ERROR("Connect Failed: " + error_name, service_path); | |
| 199 | |
| 200 // If a new connect attempt canceled this connect, no need to notify the | |
| 201 // user. | |
| 202 if (error_name == NetworkConnectionHandler::kErrorConnectCanceled) | |
| 203 return; | |
| 204 | |
| 205 if (error_name == shill::kErrorBadPassphrase || | |
| 206 error_name == NetworkConnectionHandler::kErrorPassphraseRequired || | |
| 207 error_name == NetworkConnectionHandler::kErrorConfigurationRequired || | |
| 208 error_name == NetworkConnectionHandler::kErrorAuthenticationRequired) { | |
| 209 HandleUnconfiguredNetwork(service_path); | |
| 210 return; | |
| 211 } | |
| 212 | |
| 213 if (error_name == NetworkConnectionHandler::kErrorCertificateRequired) { | |
| 214 if (!delegate_->ShowEnrollNetwork(service_path)) { | |
| 215 HandleUnconfiguredNetwork(service_path); | |
| 216 } | |
| 217 return; | |
| 218 } | |
| 219 | |
| 220 if (error_name == NetworkConnectionHandler::kErrorActivationRequired) { | |
| 221 ActivateCellular(service_path); | |
| 222 return; | |
| 223 } | |
| 224 | |
| 225 if (error_name == NetworkConnectionHandler::kErrorConnected || | |
| 226 error_name == NetworkConnectionHandler::kErrorConnecting) { | |
| 227 ShowNetworkSettings(service_path); | |
| 228 return; | |
| 229 } | |
| 230 | |
| 231 // ConnectFailed or unknown error; show a notification. | |
| 232 network_state_notifier_->ShowNetworkConnectError(error_name, service_path); | |
| 233 | |
| 234 // Only show a configure dialog if there was a ConnectFailed error. | |
| 235 if (error_name != shill::kErrorConnectFailed) | |
| 236 return; | |
| 237 | |
| 238 // If Shill reports an InProgress error, don't try to configure the network. | |
| 239 std::string dbus_error_name; | |
| 240 error_data.get()->GetString(chromeos::network_handler::kDbusErrorName, | |
| 241 &dbus_error_name); | |
| 242 if (dbus_error_name == shill::kErrorResultInProgress) | |
| 243 return; | |
| 244 | |
| 245 HandleUnconfiguredNetwork(service_path); | |
| 246 } | |
| 247 | |
| 248 void NetworkConnectImpl::OnConnectSucceeded(const std::string& service_path) { | |
| 249 NET_LOG_USER("Connect Succeeded", service_path); | |
| 250 network_state_notifier_->RemoveConnectNotification(); | |
| 251 } | |
| 252 | |
| 253 // If |check_error_state| is true, error state for the network is checked, | |
| 254 // otherwise any current error state is ignored (e.g. for recently configured | |
| 255 // networks or repeat connect attempts). | |
| 256 void NetworkConnectImpl::CallConnectToNetwork(const std::string& service_path, | |
| 257 bool check_error_state) { | |
| 258 network_state_notifier_->RemoveConnectNotification(); | |
| 259 NetworkHandler::Get()->network_connection_handler()->ConnectToNetwork( | |
| 260 service_path, base::Bind(&NetworkConnectImpl::OnConnectSucceeded, | |
| 261 weak_factory_.GetWeakPtr(), service_path), | |
| 262 base::Bind(&NetworkConnectImpl::OnConnectFailed, | |
| 263 weak_factory_.GetWeakPtr(), service_path), | |
| 264 check_error_state); | |
| 265 } | |
| 266 | |
| 267 void NetworkConnectImpl::OnActivateFailed( | |
| 268 const std::string& service_path, | |
| 269 const std::string& error_name, | |
| 270 scoped_ptr<base::DictionaryValue> error_data) { | |
| 271 NET_LOG_ERROR("Unable to activate network", service_path); | |
| 272 network_state_notifier_->ShowNetworkConnectError(kErrorActivateFailed, | |
| 273 service_path); | |
| 274 } | |
| 275 | |
| 276 void NetworkConnectImpl::OnActivateSucceeded(const std::string& service_path) { | |
| 277 NET_LOG_USER("Activation Succeeded", service_path); | |
| 278 } | |
| 279 | |
| 280 void NetworkConnectImpl::OnConfigureFailed( | |
| 281 const std::string& error_name, | |
| 282 scoped_ptr<base::DictionaryValue> error_data) { | |
| 283 NET_LOG_ERROR("Unable to configure network", ""); | |
| 284 network_state_notifier_->ShowNetworkConnectError( | |
| 285 NetworkConnectionHandler::kErrorConfigureFailed, ""); | |
| 286 } | |
| 287 | |
| 288 void NetworkConnectImpl::OnConfigureSucceeded(bool connect_on_configure, | |
| 289 const std::string& service_path) { | |
| 290 NET_LOG_USER("Configure Succeeded", service_path); | |
| 291 if (!connect_on_configure) | |
| 292 return; | |
| 293 // After configuring a network, ignore any (possibly stale) error state. | |
| 294 const bool check_error_state = false; | |
| 295 CallConnectToNetwork(service_path, check_error_state); | |
| 296 } | |
| 297 | |
| 298 void NetworkConnectImpl::CallCreateConfiguration( | |
| 299 base::DictionaryValue* properties, | |
| 300 bool shared, | |
| 301 bool connect_on_configure) { | |
| 302 std::string profile_path; | |
| 303 if (!GetNetworkProfilePath(shared, &profile_path)) { | |
| 304 network_state_notifier_->ShowNetworkConnectError( | |
| 305 NetworkConnectionHandler::kErrorConfigureFailed, ""); | |
| 306 return; | |
| 307 } | |
| 308 properties->SetStringWithoutPathExpansion(shill::kProfileProperty, | |
| 309 profile_path); | |
| 310 NetworkHandler::Get()->network_configuration_handler()->CreateConfiguration( | |
| 311 *properties, base::Bind(&NetworkConnectImpl::OnConfigureSucceeded, | |
| 312 weak_factory_.GetWeakPtr(), connect_on_configure), | |
| 313 base::Bind(&NetworkConnectImpl::OnConfigureFailed, | |
| 314 weak_factory_.GetWeakPtr())); | |
| 315 } | |
| 316 | |
| 317 void NetworkConnectImpl::SetPropertiesFailed( | |
| 318 const std::string& desc, | |
| 319 const std::string& service_path, | |
| 320 const std::string& config_error_name, | |
| 321 scoped_ptr<base::DictionaryValue> error_data) { | |
| 322 NET_LOG_ERROR(desc + ": Failed: " + config_error_name, service_path); | |
| 323 network_state_notifier_->ShowNetworkConnectError( | |
| 324 NetworkConnectionHandler::kErrorConfigureFailed, service_path); | |
| 325 } | |
| 326 | |
| 327 void NetworkConnectImpl::SetPropertiesToClear( | |
| 328 base::DictionaryValue* properties_to_set, | |
| 329 std::vector<std::string>* properties_to_clear) { | |
| 330 // Move empty string properties to properties_to_clear. | |
| 331 for (base::DictionaryValue::Iterator iter(*properties_to_set); | |
| 332 !iter.IsAtEnd(); iter.Advance()) { | |
| 333 std::string value_str; | |
| 334 if (iter.value().GetAsString(&value_str) && value_str.empty()) | |
| 335 properties_to_clear->push_back(iter.key()); | |
| 336 } | |
| 337 // Remove cleared properties from properties_to_set. | |
| 338 for (std::vector<std::string>::iterator iter = properties_to_clear->begin(); | |
| 339 iter != properties_to_clear->end(); ++iter) { | |
| 340 properties_to_set->RemoveWithoutPathExpansion(*iter, NULL); | |
| 341 } | |
| 342 } | |
| 343 | |
| 344 void NetworkConnectImpl::ClearPropertiesAndConnect( | |
| 345 const std::string& service_path, | |
| 346 const std::vector<std::string>& properties_to_clear) { | |
| 347 NET_LOG_USER("ClearPropertiesAndConnect", service_path); | |
| 348 // After configuring a network, ignore any (possibly stale) error state. | |
| 349 const bool check_error_state = false; | |
| 350 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( | |
| 351 service_path, properties_to_clear, | |
| 352 base::Bind(&NetworkConnectImpl::CallConnectToNetwork, | |
| 353 weak_factory_.GetWeakPtr(), service_path, check_error_state), | |
| 354 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, | |
| 355 weak_factory_.GetWeakPtr(), "ClearProperties", service_path)); | |
| 356 } | |
| 357 | |
| 358 void NetworkConnectImpl::ConfigureSetProfileSucceeded( | |
| 359 const std::string& service_path, | |
| 360 scoped_ptr<base::DictionaryValue> properties_to_set) { | |
| 361 std::vector<std::string> properties_to_clear; | |
| 362 SetPropertiesToClear(properties_to_set.get(), &properties_to_clear); | |
| 363 NetworkHandler::Get()->network_configuration_handler()->SetProperties( | |
| 364 service_path, *properties_to_set, | |
| 365 base::Bind(&NetworkConnectImpl::ClearPropertiesAndConnect, | |
| 366 weak_factory_.GetWeakPtr(), service_path, properties_to_clear), | |
| 367 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, | |
| 368 weak_factory_.GetWeakPtr(), "SetProperties", service_path)); | |
| 369 } | |
| 370 | |
| 371 // Public methods | |
| 372 | |
| 373 void NetworkConnectImpl::ConnectToNetwork(const std::string& service_path) { | |
| 374 NET_LOG_USER("ConnectToNetwork", service_path); | |
| 375 const NetworkState* network = GetNetworkState(service_path); | |
| 376 if (network) { | |
| 377 if (!network->error().empty() && !network->security().empty()) { | |
| 378 NET_LOG_USER("Configure: " + network->error(), service_path); | |
| 379 // If the network is in an error state, show the configuration UI | |
| 380 // directly to avoid a spurious notification. | |
| 381 HandleUnconfiguredNetwork(service_path); | |
| 382 return; | |
| 383 } else if (network->RequiresActivation()) { | |
| 384 ActivateCellular(service_path); | |
| 385 return; | |
| 386 } | |
| 387 } | |
| 388 const bool check_error_state = true; | |
| 389 CallConnectToNetwork(service_path, check_error_state); | |
| 390 } | |
| 391 | |
| 392 void NetworkConnectImpl::SetTechnologyEnabled( | |
| 393 const NetworkTypePattern& technology, | |
| 394 bool enabled_state) { | |
| 395 std::string log_string = base::StringPrintf( | |
| 396 "technology %s, target state: %s", technology.ToDebugString().c_str(), | |
| 397 (enabled_state ? "ENABLED" : "DISABLED")); | |
| 398 NET_LOG_USER("SetTechnologyEnabled", log_string); | |
| 399 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | |
| 400 bool enabled = handler->IsTechnologyEnabled(technology); | |
| 401 if (enabled_state == enabled) { | |
| 402 NET_LOG_USER("Technology already in target state.", log_string); | |
| 403 return; | |
| 404 } | |
| 405 if (enabled) { | |
| 406 // User requested to disable the technology. | |
| 407 handler->SetTechnologyEnabled(technology, false, | |
| 408 chromeos::network_handler::ErrorCallback()); | |
| 409 return; | |
| 410 } | |
| 411 // If we're dealing with a mobile network, then handle SIM lock here. | |
| 412 // SIM locking only applies to cellular, so the code below won't execute | |
| 413 // if |technology| has been explicitly set to WiMAX. | |
| 414 if (technology.MatchesPattern(NetworkTypePattern::Mobile())) { | |
| 415 const DeviceState* mobile = handler->GetDeviceStateByType(technology); | |
| 416 if (!mobile) { | |
| 417 NET_LOG_ERROR("SetTechnologyEnabled with no device", log_string); | |
| 418 return; | |
| 419 } | |
| 420 // The following only applies to cellular. | |
| 421 if (mobile->type() == shill::kTypeCellular) { | |
| 422 if (mobile->IsSimAbsent()) { | |
| 423 // If this is true, then we have a cellular device with no SIM | |
| 424 // inserted. TODO(armansito): Chrome should display a notification here, | |
| 425 // prompting the user to insert a SIM card and restart the device to | |
| 426 // enable cellular. See crbug.com/125171. | |
| 427 NET_LOG_USER("Cannot enable cellular device without SIM.", log_string); | |
| 428 return; | |
| 429 } | |
| 430 if (!mobile->sim_lock_type().empty()) { | |
| 431 // A SIM has been inserted, but it is locked. Let the user unlock it | |
| 432 // via the dialog. | |
| 433 delegate_->ShowMobileSimDialog(); | |
| 434 return; | |
| 435 } | |
| 436 } | |
| 437 } | |
| 438 handler->SetTechnologyEnabled(technology, true, | |
| 439 chromeos::network_handler::ErrorCallback()); | |
| 440 } | |
| 441 | |
| 442 void NetworkConnectImpl::ActivateCellular(const std::string& service_path) { | |
| 443 NET_LOG_USER("ActivateCellular", service_path); | |
| 444 const NetworkState* cellular = GetNetworkState(service_path); | |
| 445 if (!cellular || cellular->type() != shill::kTypeCellular) { | |
| 446 NET_LOG_ERROR("ActivateCellular with no Service", service_path); | |
| 447 return; | |
| 448 } | |
| 449 const DeviceState* cellular_device = | |
| 450 NetworkHandler::Get()->network_state_handler()->GetDeviceState( | |
| 451 cellular->device_path()); | |
| 452 if (!cellular_device) { | |
| 453 NET_LOG_ERROR("ActivateCellular with no Device", service_path); | |
| 454 return; | |
| 455 } | |
| 456 if (!IsDirectActivatedCarrier(cellular_device->carrier())) { | |
| 457 // For non direct activation, show the mobile setup dialog which can be | |
| 458 // used to activate the network. | |
| 459 ShowMobileSetup(service_path); | |
| 460 return; | |
| 461 } | |
| 462 if (cellular->activation_state() == shill::kActivationStateActivated) { | |
| 463 NET_LOG_ERROR("ActivateCellular for activated service", service_path); | |
| 464 return; | |
| 465 } | |
| 466 | |
| 467 NetworkHandler::Get()->network_activation_handler()->Activate( | |
| 468 service_path, | |
| 469 "", // carrier | |
| 470 base::Bind(&NetworkConnectImpl::OnActivateSucceeded, | |
| 471 weak_factory_.GetWeakPtr(), service_path), | |
| 472 base::Bind(&NetworkConnectImpl::OnActivateFailed, | |
| 473 weak_factory_.GetWeakPtr(), service_path)); | |
| 474 } | |
| 475 | |
| 476 void NetworkConnectImpl::ShowMobileSetup(const std::string& service_path) { | |
| 477 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | |
| 478 const NetworkState* cellular = handler->GetNetworkState(service_path); | |
| 479 if (!cellular || cellular->type() != shill::kTypeCellular) { | |
| 480 NET_LOG_ERROR("ShowMobileSetup without Cellular network", service_path); | |
| 481 return; | |
| 482 } | |
| 483 if (cellular->activation_state() != shill::kActivationStateActivated && | |
| 484 cellular->activation_type() == shill::kActivationTypeNonCellular && | |
| 485 !handler->DefaultNetwork()) { | |
| 486 network_state_notifier_->ShowMobileActivationError(service_path); | |
| 487 return; | |
| 488 } | |
| 489 delegate_->ShowMobileSetupDialog(service_path); | |
| 490 } | |
| 491 | |
| 492 void NetworkConnectImpl::ConfigureNetworkAndConnect( | |
| 493 const std::string& service_path, | |
| 494 const base::DictionaryValue& properties, | |
| 495 bool shared) { | |
| 496 NET_LOG_USER("ConfigureNetworkAndConnect", service_path); | |
| 497 | |
| 498 scoped_ptr<base::DictionaryValue> properties_to_set(properties.DeepCopy()); | |
| 499 | |
| 500 std::string profile_path; | |
| 501 if (!GetNetworkProfilePath(shared, &profile_path)) { | |
| 502 network_state_notifier_->ShowNetworkConnectError( | |
| 503 NetworkConnectionHandler::kErrorConfigureFailed, service_path); | |
| 504 return; | |
| 505 } | |
| 506 NetworkHandler::Get()->network_configuration_handler()->SetNetworkProfile( | |
| 507 service_path, profile_path, | |
| 508 base::Bind(&NetworkConnectImpl::ConfigureSetProfileSucceeded, | |
| 509 weak_factory_.GetWeakPtr(), service_path, | |
| 510 base::Passed(&properties_to_set)), | |
| 511 base::Bind(&NetworkConnectImpl::SetPropertiesFailed, | |
| 512 weak_factory_.GetWeakPtr(), "SetProfile: " + profile_path, | |
| 513 service_path)); | |
| 514 } | |
| 515 | |
| 516 void NetworkConnectImpl::CreateConfigurationAndConnect( | |
| 517 base::DictionaryValue* properties, | |
| 518 bool shared) { | |
| 519 NET_LOG_USER("CreateConfigurationAndConnect", ""); | |
| 520 CallCreateConfiguration(properties, shared, true /* connect_on_configure */); | |
| 521 } | |
| 522 | |
| 523 void NetworkConnectImpl::CreateConfiguration(base::DictionaryValue* properties, | |
| 524 bool shared) { | |
| 525 NET_LOG_USER("CreateConfiguration", ""); | |
| 526 CallCreateConfiguration(properties, shared, false /* connect_on_configure */); | |
| 527 } | |
| 528 | |
| 529 base::string16 NetworkConnectImpl::GetErrorString( | |
| 530 const std::string& error, | |
| 531 const std::string& service_path) { | |
| 532 if (error.empty()) | |
| 533 return base::string16(); | |
| 534 if (error == shill::kErrorOutOfRange) | |
| 535 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OUT_OF_RANGE); | |
| 536 if (error == shill::kErrorPinMissing) | |
| 537 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_PIN_MISSING); | |
| 538 if (error == shill::kErrorDhcpFailed) | |
| 539 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_DHCP_FAILED); | |
| 540 if (error == shill::kErrorConnectFailed) | |
| 541 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_CONNECT_FAILED); | |
| 542 if (error == shill::kErrorBadPassphrase) | |
| 543 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_PASSPHRASE); | |
| 544 if (error == shill::kErrorBadWEPKey) | |
| 545 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_BAD_WEPKEY); | |
| 546 if (error == shill::kErrorActivationFailed) { | |
| 547 return l10n_util::GetStringUTF16( | |
| 548 IDS_CHROMEOS_NETWORK_ERROR_ACTIVATION_FAILED); | |
| 549 } | |
| 550 if (error == shill::kErrorNeedEvdo) | |
| 551 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_NEED_EVDO); | |
| 552 if (error == shill::kErrorNeedHomeNetwork) { | |
| 553 return l10n_util::GetStringUTF16( | |
| 554 IDS_CHROMEOS_NETWORK_ERROR_NEED_HOME_NETWORK); | |
| 555 } | |
| 556 if (error == shill::kErrorOtaspFailed) | |
| 557 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_OTASP_FAILED); | |
| 558 if (error == shill::kErrorAaaFailed) | |
| 559 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_AAA_FAILED); | |
| 560 if (error == shill::kErrorInternal) | |
| 561 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_INTERNAL); | |
| 562 if (error == shill::kErrorDNSLookupFailed) { | |
| 563 return l10n_util::GetStringUTF16( | |
| 564 IDS_CHROMEOS_NETWORK_ERROR_DNS_LOOKUP_FAILED); | |
| 565 } | |
| 566 if (error == shill::kErrorHTTPGetFailed) { | |
| 567 return l10n_util::GetStringUTF16( | |
| 568 IDS_CHROMEOS_NETWORK_ERROR_HTTP_GET_FAILED); | |
| 569 } | |
| 570 if (error == shill::kErrorIpsecPskAuthFailed) { | |
| 571 return l10n_util::GetStringUTF16( | |
| 572 IDS_CHROMEOS_NETWORK_ERROR_IPSEC_PSK_AUTH_FAILED); | |
| 573 } | |
| 574 if (error == shill::kErrorIpsecCertAuthFailed) { | |
| 575 return l10n_util::GetStringUTF16( | |
| 576 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED); | |
| 577 } | |
| 578 if (error == shill::kErrorEapAuthenticationFailed) { | |
| 579 const NetworkState* network = GetNetworkState(service_path); | |
| 580 // TLS always requires a client certificate, so show a cert auth | |
| 581 // failed message for TLS. Other EAP methods do not generally require | |
| 582 // a client certicate. | |
| 583 if (network && network->eap_method() == shill::kEapMethodTLS) { | |
| 584 return l10n_util::GetStringUTF16( | |
| 585 IDS_CHROMEOS_NETWORK_ERROR_CERT_AUTH_FAILED); | |
| 586 } else { | |
| 587 return l10n_util::GetStringUTF16( | |
| 588 IDS_CHROMEOS_NETWORK_ERROR_EAP_AUTH_FAILED); | |
| 589 } | |
| 590 } | |
| 591 if (error == shill::kErrorEapLocalTlsFailed) { | |
| 592 return l10n_util::GetStringUTF16( | |
| 593 IDS_CHROMEOS_NETWORK_ERROR_EAP_LOCAL_TLS_FAILED); | |
| 594 } | |
| 595 if (error == shill::kErrorEapRemoteTlsFailed) { | |
| 596 return l10n_util::GetStringUTF16( | |
| 597 IDS_CHROMEOS_NETWORK_ERROR_EAP_REMOTE_TLS_FAILED); | |
| 598 } | |
| 599 if (error == shill::kErrorPppAuthFailed) { | |
| 600 return l10n_util::GetStringUTF16( | |
| 601 IDS_CHROMEOS_NETWORK_ERROR_PPP_AUTH_FAILED); | |
| 602 } | |
| 603 | |
| 604 if (base::StringToLowerASCII(error) == | |
| 605 base::StringToLowerASCII(std::string(shill::kUnknownString))) { | |
| 606 return l10n_util::GetStringUTF16(IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN); | |
| 607 } | |
| 608 return l10n_util::GetStringFUTF16(IDS_NETWORK_UNRECOGNIZED_ERROR, | |
| 609 base::UTF8ToUTF16(error)); | |
| 610 } | |
| 611 | |
| 612 void NetworkConnectImpl::ShowNetworkSettings(const std::string& service_path) { | |
| 613 delegate_->ShowNetworkSettings(service_path); | |
| 614 } | |
| 615 | |
| 616 } // namespace | |
| 617 | |
| 618 const char NetworkConnect::kErrorActivateFailed[] = "activate-failed"; | |
| 619 | |
| 620 static NetworkConnect* g_network_connect = NULL; | |
| 621 | |
| 622 // static | |
| 623 void NetworkConnect::Initialize(Delegate* delegate) { | |
| 624 CHECK(g_network_connect == NULL); | |
| 625 g_network_connect = new NetworkConnectImpl(delegate); | |
| 626 } | |
| 627 | |
| 628 // static | |
| 629 void NetworkConnect::Shutdown() { | |
| 630 CHECK(g_network_connect); | |
| 631 delete g_network_connect; | |
| 632 g_network_connect = NULL; | |
| 633 } | |
| 634 | |
| 635 // static | |
| 636 NetworkConnect* NetworkConnect::Get() { | |
| 637 CHECK(g_network_connect); | |
| 638 return g_network_connect; | |
| 639 } | |
| 640 | |
| 641 NetworkConnect::NetworkConnect() { | |
| 642 } | |
| 643 | |
| 644 NetworkConnect::~NetworkConnect() { | |
| 645 } | |
| 646 | |
| 647 } // namespace ui | |
| OLD | NEW |