internet_options_handler.cc revision 8bcbed890bc3ce4d7a057a8f32cab53fa534672e
1// Copyright (c) 2012 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 "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" 6 7#include <ctype.h> 8 9#include <map> 10#include <string> 11#include <vector> 12 13#include "ash/shell.h" 14#include "ash/shell_delegate.h" 15#include "ash/system/chromeos/network/network_connect.h" 16#include "ash/system/chromeos/network/network_icon.h" 17#include "base/base64.h" 18#include "base/basictypes.h" 19#include "base/bind.h" 20#include "base/bind_helpers.h" 21#include "base/command_line.h" 22#include "base/i18n/time_formatting.h" 23#include "base/json/json_writer.h" 24#include "base/strings/string16.h" 25#include "base/strings/string_number_conversions.h" 26#include "base/strings/stringprintf.h" 27#include "base/strings/utf_string_conversions.h" 28#include "base/time/time.h" 29#include "base/values.h" 30#include "chrome/browser/browser_process.h" 31#include "chrome/browser/chrome_notification_types.h" 32#include "chrome/browser/chromeos/choose_mobile_network_dialog.h" 33#include "chrome/browser/chromeos/enrollment_dialog_view.h" 34#include "chrome/browser/chromeos/login/user.h" 35#include "chrome/browser/chromeos/login/user_manager.h" 36#include "chrome/browser/chromeos/mobile_config.h" 37#include "chrome/browser/chromeos/net/onc_utils.h" 38#include "chrome/browser/chromeos/options/network_config_view.h" 39#include "chrome/browser/chromeos/options/network_property_ui_data.h" 40#include "chrome/browser/chromeos/settings/cros_settings.h" 41#include "chrome/browser/chromeos/sim_dialog_delegate.h" 42#include "chrome/browser/chromeos/ui_proxy_config_service.h" 43#include "chrome/browser/profiles/profile_manager.h" 44#include "chrome/browser/ui/browser.h" 45#include "chrome/browser/ui/browser_finder.h" 46#include "chrome/browser/ui/browser_window.h" 47#include "chrome/browser/ui/host_desktop.h" 48#include "chrome/browser/ui/singleton_tabs.h" 49#include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h" 50#include "chromeos/chromeos_switches.h" 51#include "chromeos/network/device_state.h" 52#include "chromeos/network/favorite_state.h" 53#include "chromeos/network/managed_network_configuration_handler.h" 54#include "chromeos/network/network_configuration_handler.h" 55#include "chromeos/network/network_connection_handler.h" 56#include "chromeos/network/network_device_handler.h" 57#include "chromeos/network/network_event_log.h" 58#include "chromeos/network/network_ip_config.h" 59#include "chromeos/network/network_profile.h" 60#include "chromeos/network/network_profile_handler.h" 61#include "chromeos/network/network_state.h" 62#include "chromeos/network/network_state_handler.h" 63#include "chromeos/network/network_ui_data.h" 64#include "chromeos/network/network_util.h" 65#include "chromeos/network/shill_property_util.h" 66#include "components/onc/onc_constants.h" 67#include "content/public/browser/notification_service.h" 68#include "content/public/browser/web_contents.h" 69#include "content/public/browser/web_contents_view.h" 70#include "content/public/browser/web_ui.h" 71#include "grit/ash_resources.h" 72#include "grit/ash_strings.h" 73#include "grit/chromium_strings.h" 74#include "grit/generated_resources.h" 75#include "grit/locale_settings.h" 76#include "grit/theme_resources.h" 77#include "third_party/cros_system_api/dbus/service_constants.h" 78#include "ui/base/l10n/l10n_util.h" 79#include "ui/base/layout.h" 80#include "ui/base/resource/resource_bundle.h" 81#include "ui/base/webui/web_ui_util.h" 82#include "ui/gfx/display.h" 83#include "ui/gfx/image/image_skia.h" 84#include "ui/gfx/screen.h" 85#include "ui/views/widget/widget.h" 86 87namespace chromeos { 88namespace options { 89 90namespace { 91 92// Keys for the network description dictionary passed to the web ui. Make sure 93// to keep the strings in sync with what the JavaScript side uses. 94const char kNetworkInfoKeyConnectable[] = "connectable"; 95const char kNetworkInfoKeyConnected[] = "connected"; 96const char kNetworkInfoKeyConnecting[] = "connecting"; 97const char kNetworkInfoKeyIconURL[] = "iconURL"; 98const char kNetworkInfoKeyNetworkName[] = "networkName"; 99const char kNetworkInfoKeyNetworkType[] = "networkType"; 100const char kNetworkInfoKeyServicePath[] = "servicePath"; 101const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; 102 103// These are keys for getting IP information from the web ui. 104const char kIpConfigAddress[] = "address"; 105const char kIpConfigPrefixLength[] = "prefixLength"; 106const char kIpConfigNetmask[] = "netmask"; 107const char kIpConfigGateway[] = "gateway"; 108const char kIpConfigNameServers[] = "nameServers"; 109const char kIpConfigAutoConfig[] = "ipAutoConfig"; 110const char kIpConfigWebProxyAutoDiscoveryUrl[] = "webProxyAutoDiscoveryUrl"; 111 112// These are types of name server selections from the web ui. 113const char kNameServerTypeAutomatic[] = "automatic"; 114const char kNameServerTypeGoogle[] = "google"; 115const char kNameServerTypeUser[] = "user"; 116 117// These are dictionary names used to send data to the web ui. 118const char kDictionaryIpConfig[] = "ipconfig"; 119const char kDictionaryStaticIp[] = "staticIP"; 120const char kDictionarySavedIp[] = "savedIP"; 121 122// Google public name servers (DNS). 123const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; 124 125// Functions we call in JavaScript. 126const char kRefreshNetworkDataFunction[] = 127 "options.network.NetworkList.refreshNetworkData"; 128const char kSetDefaultNetworkIconsFunction[] = 129 "options.network.NetworkList.setDefaultNetworkIcons"; 130const char kShowDetailedInfoFunction[] = 131 "options.internet.DetailsInternetPage.showDetailedInfo"; 132const char kUpdateConnectionDataFunction[] = 133 "options.internet.DetailsInternetPage.updateConnectionData"; 134const char kUpdateCarrierFunction[] = 135 "options.internet.DetailsInternetPage.updateCarrier"; 136const char kUpdateLoggedInUserTypeFunction[] = 137 "options.network.NetworkList.updateLoggedInUserType"; 138const char kUpdateSecurityTabFunction[] = 139 "options.internet.DetailsInternetPage.updateSecurityTab"; 140 141// These are used to register message handlers with JavaScript. 142const char kBuyDataPlanMessage[] = "buyDataPlan"; 143const char kChangePinMessage[] = "changePin"; 144const char kDisableCellularMessage[] = "disableCellular"; 145const char kDisableWifiMessage[] = "disableWifi"; 146const char kDisableWimaxMessage[] = "disableWimax"; 147const char kEnableCellularMessage[] = "enableCellular"; 148const char kEnableWifiMessage[] = "enableWifi"; 149const char kEnableWimaxMessage[] = "enableWimax"; 150const char kNetworkCommandMessage[] = "networkCommand"; 151const char kRefreshNetworksMessage[] = "refreshNetworks"; 152const char kSetApnMessage[] = "setApn"; 153const char kSetAutoConnectMessage[] = "setAutoConnect"; 154const char kSetCarrierMessage[] = "setCarrier"; 155const char kSetIPConfigMessage[] = "setIPConfig"; 156const char kSetPreferNetworkMessage[] = "setPreferNetwork"; 157const char kSetServerHostname[] = "setServerHostname"; 158const char kSetSimCardLockMessage[] = "setSimCardLock"; 159const char kShowMorePlanInfoMessage[] = "showMorePlanInfo"; 160 161// These are strings used to communicate with JavaScript. 162const char kTagActivate[] = "activate"; 163const char kTagActivationState[] = "activationState"; 164const char kTagAddConnection[] = "add"; 165const char kTagApn[] = "apn"; 166const char kTagAutoConnect[] = "autoConnect"; 167const char kTagBssid[] = "bssid"; 168const char kTagCarrierSelectFlag[] = "showCarrierSelect"; 169const char kTagCarrierUrl[] = "carrierUrl"; 170const char kTagCellular[] = "cellular"; 171const char kTagCellularAvailable[] = "cellularAvailable"; 172const char kTagCellularEnabled[] = "cellularEnabled"; 173const char kTagCellularSupportsScan[] = "cellularSupportsScan"; 174const char kTagConfigure[] = "configure"; 175const char kTagConnect[] = "connect"; 176const char kTagConnected[] = "connected"; 177const char kTagConnecting[] = "connecting"; 178const char kTagConnectionState[] = "connectionState"; 179const char kTagControlledBy[] = "controlledBy"; 180const char kTagDeviceConnected[] = "deviceConnected"; 181const char kTagDisableConnectButton[] = "disableConnectButton"; 182const char kTagDisconnect[] = "disconnect"; 183const char kTagEncryption[] = "encryption"; 184const char kTagErrorState[] = "errorState"; 185const char kTagEsn[] = "esn"; 186const char kTagFirmwareRevision[] = "firmwareRevision"; 187const char kTagForget[] = "forget"; 188const char kTagFrequency[] = "frequency"; 189const char kTagGsm[] = "gsm"; 190const char kTagHardwareAddress[] = "hardwareAddress"; 191const char kTagHardwareRevision[] = "hardwareRevision"; 192const char kTagIdentity[] = "identity"; 193const char kTagIccid[] = "iccid"; 194const char kTagImei[] = "imei"; 195const char kTagImsi[] = "imsi"; 196const char kTagLanguage[] = "language"; 197const char kTagLastGoodApn[] = "lastGoodApn"; 198const char kTagLocalizedName[] = "localizedName"; 199const char kTagManufacturer[] = "manufacturer"; 200const char kTagMdn[] = "mdn"; 201const char kTagMeid[] = "meid"; 202const char kTagMin[] = "min"; 203const char kTagModelId[] = "modelId"; 204const char kTagName[] = "name"; 205const char kTagNameServersGoogle[] = "nameServersGoogle"; 206const char kTagNameServerType[] = "nameServerType"; 207const char kTagNetworkId[] = "networkId"; 208const char kTagNetworkName[] = "networkName"; 209const char kTagNetworkTechnology[] = "networkTechnology"; 210const char kTagOperatorCode[] = "operatorCode"; 211const char kTagOperatorName[] = "operatorName"; 212const char kTagOptions[] = "options"; 213const char kTagPassword[] = "password"; 214const char kTagPolicy[] = "policy"; 215const char kTagPreferred[] = "preferred"; 216const char kTagPrlVersion[] = "prlVersion"; 217const char kTagProviderType[] = "providerType"; 218const char kTagProviderApnList[] = "providerApnList"; 219const char kTagRecommended[] = "recommended"; 220const char kTagRecommendedValue[] = "recommendedValue"; 221const char kTagRemembered[] = "remembered"; 222const char kTagRememberedList[] = "rememberedList"; 223const char kTagRestrictedPool[] = "restrictedPool"; 224const char kTagRoamingState[] = "roamingState"; 225const char kTagServerHostname[] = "serverHostname"; 226const char kTagCarriers[] = "carriers"; 227const char kTagCurrentCarrierIndex[] = "currentCarrierIndex"; 228const char kTagServiceName[] = "serviceName"; 229const char kTagServicePath[] = "servicePath"; 230const char kTagShared[] = "shared"; 231const char kTagShowActivateButton[] = "showActivateButton"; 232const char kTagShowPreferred[] = "showPreferred"; 233const char kTagShowProxy[] = "showProxy"; 234const char kTagShowStaticIPConfig[] = "showStaticIPConfig"; 235const char kTagShowViewAccountButton[] = "showViewAccountButton"; 236const char kTagSimCardLockEnabled[] = "simCardLockEnabled"; 237const char kTagSsid[] = "ssid"; 238const char kTagStrength[] = "strength"; 239const char kTagSupportUrl[] = "supportUrl"; 240const char kTagTrue[] = "true"; 241const char kTagType[] = "type"; 242const char kTagUsername[] = "username"; 243const char kTagValue[] = "value"; 244const char kTagVpn[] = "vpn"; 245const char kTagVpnList[] = "vpnList"; 246const char kTagWifi[] = "wifi"; 247const char kTagWifiAvailable[] = "wifiAvailable"; 248const char kTagWifiEnabled[] = "wifiEnabled"; 249const char kTagWimaxAvailable[] = "wimaxAvailable"; 250const char kTagWimaxEnabled[] = "wimaxEnabled"; 251const char kTagWiredList[] = "wiredList"; 252const char kTagWirelessList[] = "wirelessList"; 253 254const int kPreferredPriority = 1; 255 256void ShillError(const std::string& function, 257 const std::string& error_name, 258 scoped_ptr<base::DictionaryValue> error_data) { 259 // UpdateConnectionData may send requests for stale services; ignore 260 // these errors. 261 if (function == "UpdateConnectionData" && 262 error_name == network_handler::kDBusFailedError) 263 return; 264 NET_LOG_ERROR("Shill Error from InternetOptionsHandler: " + error_name, 265 function); 266} 267 268const NetworkState* GetNetworkState(const std::string& service_path) { 269 return NetworkHandler::Get()->network_state_handler()-> 270 GetNetworkState(service_path); 271} 272 273void SetNetworkProperty(const std::string& service_path, 274 const std::string& property, 275 base::Value* value) { 276 NET_LOG_EVENT("SetNetworkProperty: " + property, service_path); 277 base::DictionaryValue properties; 278 properties.SetWithoutPathExpansion(property, value); 279 NetworkHandler::Get()->network_configuration_handler()->SetProperties( 280 service_path, properties, 281 base::Bind(&base::DoNothing), 282 base::Bind(&ShillError, "SetNetworkProperty")); 283} 284 285std::string ActivationStateString(const std::string& activation_state) { 286 int id; 287 if (activation_state == shill::kActivationStateActivated) 288 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_ACTIVATED; 289 else if (activation_state == shill::kActivationStateActivating) 290 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_ACTIVATING; 291 else if (activation_state == shill::kActivationStateNotActivated) 292 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_NOT_ACTIVATED; 293 else if (activation_state == shill::kActivationStatePartiallyActivated) 294 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_PARTIALLY_ACTIVATED; 295 else 296 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_UNKNOWN; 297 return l10n_util::GetStringUTF8(id); 298} 299 300std::string RoamingStateString(const std::string& roaming_state) { 301 int id; 302 if (roaming_state == shill::kRoamingStateHome) 303 id = IDS_CHROMEOS_NETWORK_ROAMING_STATE_HOME; 304 else if (roaming_state == shill::kRoamingStateRoaming) 305 id = IDS_CHROMEOS_NETWORK_ROAMING_STATE_ROAMING; 306 else 307 id = IDS_CHROMEOS_NETWORK_ROAMING_STATE_UNKNOWN; 308 return l10n_util::GetStringUTF8(id); 309} 310 311std::string ConnectionStateString(const std::string& state) { 312 int id; 313 if (state == shill::kUnknownString) 314 id = IDS_CHROMEOS_NETWORK_STATE_UNKNOWN; 315 else if (state == shill::kStateIdle) 316 id = IDS_CHROMEOS_NETWORK_STATE_IDLE; 317 else if (state == shill::kStateCarrier) 318 id = IDS_CHROMEOS_NETWORK_STATE_CARRIER; 319 else if (state == shill::kStateAssociation) 320 id = IDS_CHROMEOS_NETWORK_STATE_ASSOCIATION; 321 else if (state == shill::kStateConfiguration) 322 id = IDS_CHROMEOS_NETWORK_STATE_CONFIGURATION; 323 else if (state == shill::kStateReady) 324 id = IDS_CHROMEOS_NETWORK_STATE_READY; 325 else if (state == shill::kStateDisconnect) 326 id = IDS_CHROMEOS_NETWORK_STATE_DISCONNECT; 327 else if (state == shill::kStateFailure) 328 id = IDS_CHROMEOS_NETWORK_STATE_FAILURE; 329 else if (state == shill::kStateActivationFailure) 330 id = IDS_CHROMEOS_NETWORK_STATE_ACTIVATION_FAILURE; 331 else if (state == shill::kStatePortal) 332 id = IDS_CHROMEOS_NETWORK_STATE_PORTAL; 333 else if (state == shill::kStateOnline) 334 id = IDS_CHROMEOS_NETWORK_STATE_ONLINE; 335 else 336 id = IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED; 337 return l10n_util::GetStringUTF8(id); 338} 339 340std::string LoggedInUserTypeToString( 341 LoginState::LoggedInUserType type) { 342 switch (type) { 343 case LoginState::LOGGED_IN_USER_NONE: 344 return "none"; 345 case LoginState::LOGGED_IN_USER_REGULAR: 346 return "regular"; 347 case LoginState::LOGGED_IN_USER_OWNER: 348 return "owner"; 349 case LoginState::LOGGED_IN_USER_GUEST: 350 return "guest"; 351 case LoginState::LOGGED_IN_USER_RETAIL_MODE: 352 return "retail-mode"; 353 case LoginState::LOGGED_IN_USER_PUBLIC_ACCOUNT: 354 return "public-account"; 355 case LoginState::LOGGED_IN_USER_LOCALLY_MANAGED: 356 return "locally-managed"; 357 case LoginState::LOGGED_IN_USER_KIOSK_APP: 358 return "kiosk-app"; 359 default: 360 return ""; 361 } 362} 363 364std::string EncryptionString(const std::string& security, 365 const std::string& eap_method) { 366 if (security == shill::kSecurityNone) 367 return ""; 368 if (security == shill::kSecurityWpa) 369 return "WPA"; 370 if (security == shill::kSecurityWep) 371 return "WEP"; 372 if (security == shill::kSecurityRsn) 373 return "RSN"; 374 if (security == shill::kSecurityPsk) 375 return "PSK"; 376 if (security == shill::kSecurity8021x) { 377 std::string result = "8021X"; 378 if (eap_method == shill::kEapMethodPEAP) 379 result += "PEAP"; 380 else if (eap_method == shill::kEapMethodTLS) 381 result += "TLS"; 382 else if (eap_method == shill::kEapMethodTTLS) 383 result += "TTLS"; 384 else if (eap_method == shill::kEapMethodLEAP) 385 result += "LEAP"; 386 return result; 387 } 388 return "Unknown"; 389} 390 391std::string ProviderTypeString( 392 const std::string& provider_type, 393 const base::DictionaryValue& provider_properties) { 394 int id; 395 if (provider_type == shill::kProviderL2tpIpsec) { 396 std::string client_cert_id; 397 provider_properties.GetStringWithoutPathExpansion( 398 shill::kL2tpIpsecClientCertIdProperty, &client_cert_id); 399 if (client_cert_id.empty()) 400 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK; 401 else 402 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT; 403 } else if (provider_type == shill::kProviderOpenVpn) { 404 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN; 405 } else { 406 id = IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN; 407 } 408 return l10n_util::GetStringUTF8(id); 409} 410 411bool HasPolicyForFavorite(const FavoriteState* favorite, 412 const PrefService* profile_prefs) { 413 return onc::HasPolicyForFavoriteNetwork( 414 profile_prefs, g_browser_process->local_state(), *favorite); 415} 416 417bool HasPolicyForNetwork(const NetworkState* network, 418 const PrefService* profile_prefs) { 419 const FavoriteState* favorite = 420 NetworkHandler::Get()->network_state_handler()->GetFavoriteState( 421 network->path()); 422 if (!favorite) 423 return false; 424 return HasPolicyForFavorite(favorite, profile_prefs); 425} 426 427void SetCommonNetworkInfo(const ManagedState* state, 428 const gfx::ImageSkia& icon, 429 ui::ScaleFactor icon_scale_factor, 430 base::DictionaryValue* network_info) { 431 gfx::ImageSkiaRep image_rep = 432 icon.GetRepresentation(ui::GetImageScale(icon_scale_factor)); 433 std::string icon_url = 434 icon.isNull() ? "" : webui::GetBitmapDataUrl(image_rep.sk_bitmap()); 435 network_info->SetString(kNetworkInfoKeyIconURL, icon_url); 436 437 std::string name = state->name(); 438 if (state->Matches(NetworkTypePattern::Ethernet())) 439 name = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET); 440 network_info->SetString(kNetworkInfoKeyNetworkName, name); 441 network_info->SetString(kNetworkInfoKeyNetworkType, state->type()); 442 network_info->SetString(kNetworkInfoKeyServicePath, state->path()); 443} 444 445// Builds a dictionary with network information and an icon used for the 446// NetworkList on the settings page. Ownership of the returned pointer is 447// transferred to the caller. 448base::DictionaryValue* BuildNetworkDictionary( 449 const NetworkState* network, 450 ui::ScaleFactor icon_scale_factor, 451 const PrefService* profile_prefs) { 452 scoped_ptr<base::DictionaryValue> network_info(new base::DictionaryValue()); 453 network_info->SetBoolean(kNetworkInfoKeyConnectable, network->connectable()); 454 network_info->SetBoolean(kNetworkInfoKeyConnected, 455 network->IsConnectedState()); 456 network_info->SetBoolean(kNetworkInfoKeyConnecting, 457 network->IsConnectingState()); 458 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, 459 HasPolicyForNetwork(network, profile_prefs)); 460 461 gfx::ImageSkia icon = ash::network_icon::GetImageForNetwork( 462 network, ash::network_icon::ICON_TYPE_LIST); 463 SetCommonNetworkInfo(network, icon, icon_scale_factor, network_info.get()); 464 return network_info.release(); 465} 466 467base::DictionaryValue* BuildFavoriteDictionary( 468 const FavoriteState* favorite, 469 ui::ScaleFactor icon_scale_factor, 470 const PrefService* profile_prefs) { 471 scoped_ptr<base::DictionaryValue> network_info(new base::DictionaryValue()); 472 network_info->SetBoolean(kNetworkInfoKeyConnectable, false); 473 network_info->SetBoolean(kNetworkInfoKeyConnected, false); 474 network_info->SetBoolean(kNetworkInfoKeyConnecting, false); 475 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, 476 HasPolicyForFavorite(favorite, profile_prefs)); 477 478 gfx::ImageSkia icon = ash::network_icon::GetImageForDisconnectedNetwork( 479 ash::network_icon::ICON_TYPE_LIST, favorite->type()); 480 SetCommonNetworkInfo(favorite, icon, icon_scale_factor, network_info.get()); 481 return network_info.release(); 482} 483 484// Pulls IP information out of a shill service properties dictionary. If 485// |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it 486// fetches "SavedIP.*" properties. Caller must take ownership of returned 487// dictionary. If non-NULL, |ip_parameters_set| returns a count of the number 488// of IP routing parameters that get set. 489base::DictionaryValue* BuildIPInfoDictionary( 490 const base::DictionaryValue& shill_properties, 491 bool static_ip, 492 int* routing_parameters_set) { 493 std::string address_key; 494 std::string prefix_len_key; 495 std::string gateway_key; 496 std::string name_servers_key; 497 if (static_ip) { 498 address_key = shill::kStaticIPAddressProperty; 499 prefix_len_key = shill::kStaticIPPrefixlenProperty; 500 gateway_key = shill::kStaticIPGatewayProperty; 501 name_servers_key = shill::kStaticIPNameServersProperty; 502 } else { 503 address_key = shill::kSavedIPAddressProperty; 504 prefix_len_key = shill::kSavedIPPrefixlenProperty; 505 gateway_key = shill::kSavedIPGatewayProperty; 506 name_servers_key = shill::kSavedIPNameServersProperty; 507 } 508 509 scoped_ptr<base::DictionaryValue> ip_info_dict(new base::DictionaryValue); 510 std::string address; 511 int routing_parameters = 0; 512 if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) { 513 ip_info_dict->SetString(kIpConfigAddress, address); 514 VLOG(2) << "Found " << address_key << ": " << address; 515 routing_parameters++; 516 } 517 int prefix_len = -1; 518 if (shill_properties.GetIntegerWithoutPathExpansion( 519 prefix_len_key, &prefix_len)) { 520 ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len); 521 std::string netmask = network_util::PrefixLengthToNetmask(prefix_len); 522 ip_info_dict->SetString(kIpConfigNetmask, netmask); 523 VLOG(2) << "Found " << prefix_len_key << ": " 524 << prefix_len << " (" << netmask << ")"; 525 routing_parameters++; 526 } 527 std::string gateway; 528 if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) { 529 ip_info_dict->SetString(kIpConfigGateway, gateway); 530 VLOG(2) << "Found " << gateway_key << ": " << gateway; 531 routing_parameters++; 532 } 533 if (routing_parameters_set) 534 *routing_parameters_set = routing_parameters; 535 536 std::string name_servers; 537 if (shill_properties.GetStringWithoutPathExpansion( 538 name_servers_key, &name_servers)) { 539 ip_info_dict->SetString(kIpConfigNameServers, name_servers); 540 VLOG(2) << "Found " << name_servers_key << ": " << name_servers; 541 } 542 543 return ip_info_dict.release(); 544} 545 546bool CanForgetNetworkType(const std::string& type) { 547 return type == shill::kTypeWifi || 548 type == shill::kTypeWimax || 549 type == shill::kTypeVPN; 550} 551 552bool CanAddNetworkType(const std::string& type) { 553 return type == shill::kTypeWifi || 554 type == shill::kTypeVPN || 555 type == shill::kTypeCellular; 556} 557 558// Decorate dictionary |value_dict| with policy information from |ui_data|. 559void DecorateValueDictionary(const NetworkPropertyUIData& ui_data, 560 const base::Value& value, 561 base::DictionaryValue* value_dict) { 562 const base::Value* recommended_value = ui_data.default_value(); 563 if (ui_data.IsManaged()) 564 value_dict->SetString(kTagControlledBy, kTagPolicy); 565 else if (recommended_value && recommended_value->Equals(&value)) 566 value_dict->SetString(kTagControlledBy, kTagRecommended); 567 568 if (recommended_value) 569 value_dict->Set(kTagRecommendedValue, recommended_value->DeepCopy()); 570} 571 572// Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and 573// store it under |key| in |settings|. Takes ownership of |value|. 574void SetValueDictionary(base::DictionaryValue* settings, 575 const char* key, 576 base::Value* value, 577 const NetworkPropertyUIData& ui_data) { 578 base::DictionaryValue* dict = new base::DictionaryValue(); 579 // DictionaryValue::Set() takes ownership of |value|. 580 dict->Set(kTagValue, value); 581 settings->Set(key, dict); 582 DecorateValueDictionary(ui_data, *value, dict); 583} 584 585// Creates a decorated dictionary like SetValueDictionary does, but extended for 586// the Autoconnect property, which respects additionally global network policy. 587void SetAutoconnectValueDictionary(bool network_is_private, 588 ::onc::ONCSource onc_source, 589 bool current_autoconnect, 590 const NetworkPropertyUIData& ui_data, 591 base::DictionaryValue* settings) { 592 base::DictionaryValue* dict = new base::DictionaryValue(); 593 base::Value* value = new base::FundamentalValue(current_autoconnect); 594 // DictionaryValue::Set() takes ownership of |value|. 595 dict->Set(kTagValue, value); 596 settings->Set(kTagAutoConnect, dict); 597 if (onc_source != ::onc::ONC_SOURCE_USER_POLICY && 598 onc_source != ::onc::ONC_SOURCE_DEVICE_POLICY) { 599 // Autoconnect can be controlled by the GlobalNetworkConfiguration of the 600 // ONC policy. 601 bool only_policy_autoconnect = 602 onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(network_is_private); 603 if (only_policy_autoconnect) { 604 dict->SetString(kTagControlledBy, kTagPolicy); 605 return; 606 } 607 } 608 DecorateValueDictionary(ui_data, *value, dict); 609} 610 611std::string CopyStringFromDictionary(const base::DictionaryValue& source, 612 const std::string& src_key, 613 const std::string& dest_key, 614 base::DictionaryValue* dest) { 615 std::string string_value; 616 if (source.GetStringWithoutPathExpansion(src_key, &string_value)) 617 dest->SetStringWithoutPathExpansion(dest_key, string_value); 618 return string_value; 619} 620 621void CopyIntegerFromDictionary(const base::DictionaryValue& source, 622 const std::string& src_key, 623 const std::string& dest_key, 624 bool as_string, 625 base::DictionaryValue* dest) { 626 int int_value; 627 if (!source.GetIntegerWithoutPathExpansion(src_key, &int_value)) 628 return; 629 if (as_string) { 630 std::string str = base::StringPrintf("%d", int_value); 631 dest->SetStringWithoutPathExpansion(dest_key, str); 632 } else { 633 dest->SetIntegerWithoutPathExpansion(dest_key, int_value); 634 } 635} 636 637// Fills |dictionary| with the configuration details of |vpn|. |onc| is required 638// for augmenting the policy-managed information. 639void PopulateVPNDetails(const NetworkState* vpn, 640 const base::DictionaryValue& shill_properties, 641 base::DictionaryValue* dictionary) { 642 // Name and Remembered are set in PopulateConnectionDetails(). 643 // Provider properties are stored in the "Provider" dictionary. 644 const base::DictionaryValue* provider_properties = NULL; 645 if (!shill_properties.GetDictionaryWithoutPathExpansion( 646 shill::kProviderProperty, &provider_properties)) { 647 LOG(ERROR) << "No provider properties for VPN: " << vpn->path(); 648 return; 649 } 650 std::string provider_type; 651 provider_properties->GetStringWithoutPathExpansion( 652 shill::kTypeProperty, &provider_type); 653 dictionary->SetString(kTagProviderType, 654 ProviderTypeString(provider_type, 655 *provider_properties)); 656 657 std::string username; 658 if (provider_type == shill::kProviderOpenVpn) { 659 provider_properties->GetStringWithoutPathExpansion( 660 shill::kOpenVPNUserProperty, &username); 661 } else { 662 provider_properties->GetStringWithoutPathExpansion( 663 shill::kL2tpIpsecUserProperty, &username); 664 } 665 dictionary->SetString(kTagUsername, username); 666 667 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE; 668 const base::DictionaryValue* onc = 669 onc::FindPolicyForActiveUser(vpn->guid(), &onc_source); 670 671 NetworkPropertyUIData hostname_ui_data; 672 hostname_ui_data.ParseOncProperty( 673 onc_source, 674 onc, 675 base::StringPrintf("%s.%s", ::onc::network_config::kVPN, 676 ::onc::vpn::kHost)); 677 std::string provider_host; 678 provider_properties->GetStringWithoutPathExpansion( 679 shill::kHostProperty, &provider_host); 680 SetValueDictionary(dictionary, kTagServerHostname, 681 new base::StringValue(provider_host), 682 hostname_ui_data); 683 684 // Disable 'Connect' for VPN unless connected to a non-VPN network. 685 const NetworkState* connected_network = 686 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( 687 NetworkTypePattern::NonVirtual()); 688 dictionary->SetBoolean(kTagDisableConnectButton, !connected_network); 689} 690 691// Given a list of supported carrier's by the device, return the index of 692// the carrier the device is currently using. 693int FindCurrentCarrierIndex(const base::ListValue* carriers, 694 const DeviceState* device) { 695 DCHECK(carriers); 696 DCHECK(device); 697 bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm); 698 int index = 0; 699 for (base::ListValue::const_iterator it = carriers->begin(); 700 it != carriers->end(); ++it, ++index) { 701 std::string value; 702 if (!(*it)->GetAsString(&value)) 703 continue; 704 // For GSM devices the device name will be empty, so simply select 705 // the Generic UMTS carrier option if present. 706 if (gsm && (value == shill::kCarrierGenericUMTS)) 707 return index; 708 // For other carriers, the service name will match the carrier name. 709 if (value == device->carrier()) 710 return index; 711 } 712 return -1; 713} 714 715void PopulateWifiDetails(const NetworkState* wifi, 716 const base::DictionaryValue& shill_properties, 717 base::DictionaryValue* dictionary); 718// TODO(stevenjb): Move implementation here. 719 720void PopulateWimaxDetails(const NetworkState* wimax, 721 const base::DictionaryValue& shill_properties, 722 base::DictionaryValue* dictionary); 723// TODO(stevenjb): Move implementation here. 724 725void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn, 726 base::DictionaryValue* dictionary); 727// TODO(stevenjb): Move implementation here. 728 729void PopulateCellularDetails(const NetworkState* cellular, 730 const base::DictionaryValue& shill_properties, 731 base::DictionaryValue* dictionary); 732// TODO(stevenjb): Move implementation here. 733 734void PopulateConnectionDetails(const NetworkState* network, 735 const base::DictionaryValue& shill_properties, 736 base::DictionaryValue* dictionary); 737// TODO(stevenjb): Move implementation here. 738 739// Helper methods for SetIPConfigProperties 740bool AppendPropertyKeyIfPresent(const std::string& key, 741 const base::DictionaryValue& old_properties, 742 std::vector<std::string>* property_keys) { 743 if (old_properties.HasKey(key)) { 744 property_keys->push_back(key); 745 return true; 746 } 747 return false; 748} 749 750bool AddStringPropertyIfChanged(const std::string& key, 751 const std::string& new_value, 752 const base::DictionaryValue& old_properties, 753 base::DictionaryValue* new_properties) { 754 std::string old_value; 755 if (!old_properties.GetStringWithoutPathExpansion(key, &old_value) || 756 new_value != old_value) { 757 new_properties->SetStringWithoutPathExpansion(key, new_value); 758 return true; 759 } 760 return false; 761} 762 763bool AddIntegerPropertyIfChanged(const std::string& key, 764 int new_value, 765 const base::DictionaryValue& old_properties, 766 base::DictionaryValue* new_properties) { 767 int old_value; 768 if (!old_properties.GetIntegerWithoutPathExpansion(key, &old_value) || 769 new_value != old_value) { 770 new_properties->SetIntegerWithoutPathExpansion(key, new_value); 771 return true; 772 } 773 return false; 774} 775 776void RequestReconnect(const std::string& service_path, 777 gfx::NativeWindow owning_window) { 778 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( 779 service_path, 780 base::Bind(&ash::network_connect::ConnectToNetwork, 781 service_path, owning_window), 782 base::Bind(&ShillError, "RequestReconnect")); 783} 784 785} // namespace 786 787InternetOptionsHandler::InternetOptionsHandler() 788 : weak_factory_(this) { 789 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, 790 content::NotificationService::AllSources()); 791 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED, 792 content::NotificationService::AllSources()); 793 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE); 794 LoginState::Get()->AddObserver(this); 795} 796 797InternetOptionsHandler::~InternetOptionsHandler() { 798 if (NetworkHandler::IsInitialized()) { 799 NetworkHandler::Get()->network_state_handler()->RemoveObserver( 800 this, FROM_HERE); 801 } 802 if (LoginState::Get()->IsInitialized()) 803 LoginState::Get()->RemoveObserver(this); 804} 805 806void InternetOptionsHandler::GetLocalizedValues( 807 base::DictionaryValue* localized_strings) { 808 DCHECK(localized_strings); 809 810 static OptionsStringResource resources[] = { 811 812 // Main settings page. 813 814 { "ethernetTitle", IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET }, 815 { "wifiTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIFI_NETWORK }, 816 { "wimaxTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIMAX_NETWORK }, 817 { "cellularTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_CELLULAR_NETWORK }, 818 { "vpnTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_PRIVATE_NETWORK }, 819 { "networkNotConnected", IDS_OPTIONS_SETTINGS_NETWORK_NOT_CONNECTED }, 820 { "networkConnected", IDS_CHROMEOS_NETWORK_STATE_READY }, 821 { "joinOtherNetwork", IDS_OPTIONS_SETTINGS_NETWORK_OTHER }, 822 { "networkOffline", IDS_OPTIONS_SETTINGS_NETWORK_OFFLINE }, 823 { "networkDisabled", IDS_OPTIONS_SETTINGS_NETWORK_DISABLED }, 824 { "networkOnline", IDS_OPTIONS_SETTINGS_NETWORK_ONLINE }, 825 { "networkOptions", IDS_OPTIONS_SETTINGS_NETWORK_OPTIONS }, 826 { "turnOffWifi", IDS_OPTIONS_SETTINGS_NETWORK_DISABLE_WIFI }, 827 { "turnOffWimax", IDS_OPTIONS_SETTINGS_NETWORK_DISABLE_WIMAX }, 828 { "turnOffCellular", IDS_OPTIONS_SETTINGS_NETWORK_DISABLE_CELLULAR }, 829 { "disconnectNetwork", IDS_OPTIONS_SETTINGS_DISCONNECT }, 830 { "preferredNetworks", IDS_OPTIONS_SETTINGS_PREFERRED_NETWORKS_LABEL }, 831 { "preferredNetworksPage", IDS_OPTIONS_SETTINGS_PREFERRED_NETWORKS_TITLE }, 832 { "useSharedProxies", IDS_OPTIONS_SETTINGS_USE_SHARED_PROXIES }, 833 { "addConnectionTitle", 834 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ADD_CONNECTION }, 835 { "addConnectionWifi", IDS_OPTIONS_SETTINGS_ADD_CONNECTION_WIFI }, 836 { "addConnectionVPN", IDS_STATUSBAR_NETWORK_ADD_VPN }, 837 { "otherCellularNetworks", IDS_OPTIONS_SETTINGS_OTHER_CELLULAR_NETWORKS }, 838 { "enableDataRoaming", IDS_OPTIONS_SETTINGS_ENABLE_DATA_ROAMING }, 839 { "disableDataRoaming", IDS_OPTIONS_SETTINGS_DISABLE_DATA_ROAMING }, 840 { "dataRoamingDisableToggleTooltip", 841 IDS_OPTIONS_SETTINGS_TOGGLE_DATA_ROAMING_RESTRICTION }, 842 { "activateNetwork", IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE }, 843 844 // Internet details dialog. 845 846 { "changeProxyButton", 847 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON }, 848 { "managedNetwork", IDS_OPTIONS_SETTINGS_MANAGED_NETWORK }, 849 { "wifiNetworkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, 850 { "vpnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN }, 851 { "cellularConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION }, 852 { "cellularDeviceTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE }, 853 { "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK }, 854 { "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY }, 855 { "proxyTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PROXY }, 856 { "connectionState", IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE }, 857 { "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS }, 858 { "inetNetmask", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK }, 859 { "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY }, 860 { "inetNameServers", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER }, 861 { "ipAutomaticConfiguration", 862 IDS_OPTIONS_SETTINGS_INTERNET_IP_AUTOMATIC_CONFIGURATION }, 863 { "automaticNameServers", 864 IDS_OPTIONS_SETTINGS_INTERNET_AUTOMATIC_NAME_SERVERS }, 865 { "userNameServer1", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_1 }, 866 { "userNameServer2", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_2 }, 867 { "userNameServer3", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_3 }, 868 { "userNameServer4", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_4 }, 869 { "googleNameServers", IDS_OPTIONS_SETTINGS_INTERNET_GOOGLE_NAME_SERVERS }, 870 { "userNameServers", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVERS }, 871 { "hardwareAddress", 872 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS }, 873 { "detailsInternetDismiss", IDS_CLOSE }, 874 { "activateButton", IDS_OPTIONS_SETTINGS_ACTIVATE }, 875 { "buyplanButton", IDS_OPTIONS_SETTINGS_BUY_PLAN }, 876 { "connectButton", IDS_OPTIONS_SETTINGS_CONNECT }, 877 { "configureButton", IDS_OPTIONS_SETTINGS_CONFIGURE }, 878 { "disconnectButton", IDS_OPTIONS_SETTINGS_DISCONNECT }, 879 { "viewAccountButton", IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT }, 880 { "wimaxConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_WIMAX }, 881 882 // Wifi Tab. 883 884 { "inetSsid", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID }, 885 { "inetBssid", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_BSSID }, 886 { "inetEncryption", 887 IDS_OPTIONS_SETTIGNS_INTERNET_OPTIONS_NETWORK_ENCRYPTION }, 888 { "inetFrequency", 889 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_FREQUENCY }, 890 { "inetFrequencyFormat", 891 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_FREQUENCY_MHZ }, 892 { "inetSignalStrength", 893 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_STRENGTH }, 894 { "inetSignalStrengthFormat", 895 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_STRENGTH_PERCENTAGE }, 896 { "inetPassProtected", 897 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NET_PROTECTED }, 898 { "inetNetworkShared", 899 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_SHARED }, 900 { "inetPreferredNetwork", 901 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PREFER_NETWORK }, 902 { "inetAutoConnectNetwork", 903 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT }, 904 { "inetLogin", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOGIN }, 905 { "inetShowPass", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOWPASSWORD }, 906 { "inetPassPrompt", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSWORD }, 907 { "inetSsidPrompt", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SSID }, 908 { "inetStatus", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_STATUS_TITLE }, 909 { "inetConnect", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CONNECT_TITLE }, 910 911 // VPN Tab. 912 913 { "inetServiceName", 914 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME }, 915 { "inetServerHostname", 916 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME }, 917 { "inetProviderType", 918 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE }, 919 { "inetUsername", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME }, 920 921 // Cellular Tab. 922 923 { "serviceName", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_SERVICE_NAME }, 924 { "networkTechnology", 925 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_NETWORK_TECHNOLOGY }, 926 { "operatorName", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR }, 927 { "operatorCode", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR_CODE }, 928 { "activationState", 929 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACTIVATION_STATE }, 930 { "roamingState", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ROAMING_STATE }, 931 { "restrictedPool", 932 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_RESTRICTED_POOL }, 933 { "errorState", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ERROR_STATE }, 934 { "manufacturer", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MANUFACTURER }, 935 { "modelId", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MODEL_ID }, 936 { "firmwareRevision", 937 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_FIRMWARE_REVISION }, 938 { "hardwareRevision", 939 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_HARDWARE_REVISION }, 940 { "prlVersion", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_PRL_VERSION }, 941 { "cellularApnLabel", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN }, 942 { "cellularApnOther", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_OTHER }, 943 { "cellularApnUsername", 944 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_USERNAME }, 945 { "cellularApnPassword", 946 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_PASSWORD }, 947 { "cellularApnUseDefault", 948 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_CLEAR }, 949 { "cellularApnSet", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_SET }, 950 { "cellularApnCancel", IDS_CANCEL }, 951 952 // Security Tab. 953 954 { "accessSecurityTabLink", 955 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACCESS_SECURITY_TAB }, 956 { "lockSimCard", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_LOCK_SIM_CARD }, 957 { "changePinButton", 958 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_BUTTON }, 959 960 // Proxy Tab. 961 { "webProxyAutoDiscoveryUrl", IDS_PROXY_WEB_PROXY_AUTO_DISCOVERY }, 962 }; 963 964 RegisterStrings(localized_strings, resources, arraysize(resources)); 965 966 std::string owner; 967 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); 968 localized_strings->SetString("ownerUserId", UTF8ToUTF16(owner)); 969 970 base::DictionaryValue* network_dictionary = new base::DictionaryValue; 971 FillNetworkInfo(network_dictionary); 972 localized_strings->Set("networkData", network_dictionary); 973} 974 975void InternetOptionsHandler::InitializePage() { 976 base::DictionaryValue dictionary; 977 dictionary.SetString(kTagCellular, 978 GetIconDataUrl(IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK)); 979 dictionary.SetString(kTagWifi, 980 GetIconDataUrl(IDR_AURA_UBER_TRAY_NETWORK_ARCS_DARK)); 981 dictionary.SetString(kTagVpn, 982 GetIconDataUrl(IDR_AURA_UBER_TRAY_NETWORK_VPN)); 983 web_ui()->CallJavascriptFunction(kSetDefaultNetworkIconsFunction, 984 dictionary); 985 NetworkHandler::Get()->network_state_handler()->RequestScan(); 986 RefreshNetworkData(); 987 UpdateLoggedInUserType(); 988} 989 990void InternetOptionsHandler::RegisterMessages() { 991 // Setup handlers specific to this panel. 992 web_ui()->RegisterMessageCallback(kNetworkCommandMessage, 993 base::Bind(&InternetOptionsHandler::NetworkCommandCallback, 994 base::Unretained(this))); 995 web_ui()->RegisterMessageCallback(kRefreshNetworksMessage, 996 base::Bind(&InternetOptionsHandler::RefreshNetworksCallback, 997 base::Unretained(this))); 998 web_ui()->RegisterMessageCallback(kSetPreferNetworkMessage, 999 base::Bind(&InternetOptionsHandler::SetPreferNetworkCallback, 1000 base::Unretained(this))); 1001 web_ui()->RegisterMessageCallback(kSetAutoConnectMessage, 1002 base::Bind(&InternetOptionsHandler::SetAutoConnectCallback, 1003 base::Unretained(this))); 1004 web_ui()->RegisterMessageCallback(kSetIPConfigMessage, 1005 base::Bind(&InternetOptionsHandler::SetIPConfigCallback, 1006 base::Unretained(this))); 1007 web_ui()->RegisterMessageCallback(kEnableWifiMessage, 1008 base::Bind(&InternetOptionsHandler::EnableWifiCallback, 1009 base::Unretained(this))); 1010 web_ui()->RegisterMessageCallback(kDisableWifiMessage, 1011 base::Bind(&InternetOptionsHandler::DisableWifiCallback, 1012 base::Unretained(this))); 1013 web_ui()->RegisterMessageCallback(kEnableCellularMessage, 1014 base::Bind(&InternetOptionsHandler::EnableCellularCallback, 1015 base::Unretained(this))); 1016 web_ui()->RegisterMessageCallback(kDisableCellularMessage, 1017 base::Bind(&InternetOptionsHandler::DisableCellularCallback, 1018 base::Unretained(this))); 1019 web_ui()->RegisterMessageCallback(kEnableWimaxMessage, 1020 base::Bind(&InternetOptionsHandler::EnableWimaxCallback, 1021 base::Unretained(this))); 1022 web_ui()->RegisterMessageCallback(kDisableWimaxMessage, 1023 base::Bind(&InternetOptionsHandler::DisableWimaxCallback, 1024 base::Unretained(this))); 1025 web_ui()->RegisterMessageCallback(kBuyDataPlanMessage, 1026 base::Bind(&InternetOptionsHandler::BuyDataPlanCallback, 1027 base::Unretained(this))); 1028 web_ui()->RegisterMessageCallback(kShowMorePlanInfoMessage, 1029 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback, 1030 base::Unretained(this))); 1031 web_ui()->RegisterMessageCallback(kSetApnMessage, 1032 base::Bind(&InternetOptionsHandler::SetApnCallback, 1033 base::Unretained(this))); 1034 web_ui()->RegisterMessageCallback(kSetCarrierMessage, 1035 base::Bind(&InternetOptionsHandler::SetCarrierCallback, 1036 base::Unretained(this))); 1037 web_ui()->RegisterMessageCallback(kSetSimCardLockMessage, 1038 base::Bind(&InternetOptionsHandler::SetSimCardLockCallback, 1039 base::Unretained(this))); 1040 web_ui()->RegisterMessageCallback(kChangePinMessage, 1041 base::Bind(&InternetOptionsHandler::ChangePinCallback, 1042 base::Unretained(this))); 1043 web_ui()->RegisterMessageCallback(kSetServerHostname, 1044 base::Bind(&InternetOptionsHandler::SetServerHostnameCallback, 1045 base::Unretained(this))); 1046} 1047 1048void InternetOptionsHandler::EnableWifiCallback(const base::ListValue* args) { 1049 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( 1050 NetworkTypePattern::WiFi(), true, 1051 base::Bind(&ShillError, "EnableWifiCallback")); 1052} 1053 1054void InternetOptionsHandler::DisableWifiCallback(const base::ListValue* args) { 1055 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( 1056 NetworkTypePattern::WiFi(), false, 1057 base::Bind(&ShillError, "DisableWifiCallback")); 1058} 1059 1060void InternetOptionsHandler::EnableCellularCallback( 1061 const base::ListValue* args) { 1062 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 1063 const DeviceState* device = 1064 handler->GetDeviceStateByType(NetworkTypePattern::Cellular()); 1065 if (!device) { 1066 LOG(ERROR) << "Mobile device not found."; 1067 return; 1068 } 1069 if (!device->sim_lock_type().empty()) { 1070 SimDialogDelegate::ShowDialog(GetNativeWindow(), 1071 SimDialogDelegate::SIM_DIALOG_UNLOCK); 1072 return; 1073 } 1074 if (!handler->IsTechnologyEnabled(NetworkTypePattern::Cellular())) { 1075 handler->SetTechnologyEnabled( 1076 NetworkTypePattern::Cellular(), true, 1077 base::Bind(&ShillError, "EnableCellularCallback")); 1078 return; 1079 } 1080 if (device->IsSimAbsent()) { 1081 MobileConfig* config = MobileConfig::GetInstance(); 1082 if (config->IsReady()) { 1083 const MobileConfig::LocaleConfig* locale_config = 1084 config->GetLocaleConfig(); 1085 if (locale_config) { 1086 std::string setup_url = locale_config->setup_url(); 1087 if (!setup_url.empty()) { 1088 chrome::ShowSingletonTab(GetAppropriateBrowser(), GURL(setup_url)); 1089 return; 1090 } 1091 } 1092 } 1093 // TODO(nkostylev): Show generic error message. http://crosbug.com/15444 1094 } 1095 LOG(ERROR) << "EnableCellularCallback called for enabled mobile device"; 1096} 1097 1098void InternetOptionsHandler::DisableCellularCallback( 1099 const base::ListValue* args) { 1100 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( 1101 NetworkTypePattern::Mobile(), false, 1102 base::Bind(&ShillError, "DisableCellularCallback")); 1103} 1104 1105void InternetOptionsHandler::EnableWimaxCallback(const base::ListValue* args) { 1106 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( 1107 NetworkTypePattern::Wimax(), true, 1108 base::Bind(&ShillError, "EnableWimaxCallback")); 1109} 1110 1111void InternetOptionsHandler::DisableWimaxCallback(const base::ListValue* args) { 1112 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled( 1113 NetworkTypePattern::Wimax(), false, 1114 base::Bind(&ShillError, "DisableWimaxCallback")); 1115} 1116 1117void InternetOptionsHandler::ShowMorePlanInfoCallback( 1118 const base::ListValue* args) { 1119 if (!web_ui()) 1120 return; 1121 std::string service_path; 1122 if (args->GetSize() != 1 || !args->GetString(0, &service_path)) { 1123 NOTREACHED(); 1124 return; 1125 } 1126 ash::network_connect::ShowMobileSetup(service_path); 1127} 1128 1129void InternetOptionsHandler::BuyDataPlanCallback(const base::ListValue* args) { 1130 if (!web_ui()) 1131 return; 1132 std::string service_path; 1133 if (args->GetSize() != 1 || !args->GetString(0, &service_path)) { 1134 NOTREACHED(); 1135 return; 1136 } 1137 ash::network_connect::ShowMobileSetup(service_path); 1138} 1139 1140void InternetOptionsHandler::SetApnCallback(const base::ListValue* args) { 1141 std::string service_path; 1142 if (!args->GetString(0, &service_path)) { 1143 NOTREACHED(); 1144 return; 1145 } 1146 NetworkHandler::Get()->network_configuration_handler()->GetProperties( 1147 service_path, 1148 base::Bind(&InternetOptionsHandler::SetApnProperties, 1149 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())), 1150 base::Bind(&ShillError, "SetApnCallback")); 1151} 1152 1153void InternetOptionsHandler::SetApnProperties( 1154 const base::ListValue* args, 1155 const std::string& service_path, 1156 const base::DictionaryValue& shill_properties) { 1157 std::string apn, username, password; 1158 if (!args->GetString(1, &apn) || 1159 !args->GetString(2, &username) || 1160 !args->GetString(3, &password)) { 1161 NOTREACHED(); 1162 return; 1163 } 1164 NET_LOG_EVENT("SetApnCallback", service_path); 1165 1166 if (apn.empty()) { 1167 std::vector<std::string> properties_to_clear; 1168 properties_to_clear.push_back(shill::kCellularApnProperty); 1169 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( 1170 service_path, properties_to_clear, 1171 base::Bind(&base::DoNothing), 1172 base::Bind(&ShillError, "ClearCellularApnProperties")); 1173 return; 1174 } 1175 1176 const base::DictionaryValue* shill_apn_dict = NULL; 1177 std::string network_id; 1178 if (shill_properties.GetDictionaryWithoutPathExpansion( 1179 shill::kCellularApnProperty, &shill_apn_dict)) { 1180 shill_apn_dict->GetStringWithoutPathExpansion( 1181 shill::kApnNetworkIdProperty, &network_id); 1182 } 1183 base::DictionaryValue properties; 1184 base::DictionaryValue* apn_dict = new base::DictionaryValue; 1185 apn_dict->SetStringWithoutPathExpansion(shill::kApnProperty, apn); 1186 apn_dict->SetStringWithoutPathExpansion(shill::kApnNetworkIdProperty, 1187 network_id); 1188 apn_dict->SetStringWithoutPathExpansion(shill::kApnUsernameProperty, 1189 username); 1190 apn_dict->SetStringWithoutPathExpansion(shill::kApnPasswordProperty, 1191 password); 1192 properties.SetWithoutPathExpansion(shill::kCellularApnProperty, apn_dict); 1193 NetworkHandler::Get()->network_configuration_handler()->SetProperties( 1194 service_path, properties, 1195 base::Bind(&base::DoNothing), 1196 base::Bind(&ShillError, "SetApnProperties")); 1197} 1198 1199void InternetOptionsHandler::CarrierStatusCallback() { 1200 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 1201 const DeviceState* device = 1202 handler->GetDeviceStateByType(NetworkTypePattern::Cellular()); 1203 if (device && (device->carrier() == shill::kCarrierSprint)) { 1204 const NetworkState* network = 1205 handler->FirstNetworkByType(NetworkTypePattern::Cellular()); 1206 if (network) { 1207 ash::network_connect::ActivateCellular(network->path()); 1208 UpdateConnectionData(network->path()); 1209 } 1210 } 1211 UpdateCarrier(); 1212} 1213 1214void InternetOptionsHandler::SetCarrierCallback(const base::ListValue* args) { 1215 std::string service_path; 1216 std::string carrier; 1217 if (args->GetSize() != 2 || 1218 !args->GetString(0, &service_path) || 1219 !args->GetString(1, &carrier)) { 1220 NOTREACHED(); 1221 return; 1222 } 1223 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> 1224 GetDeviceStateByType(NetworkTypePattern::Cellular()); 1225 if (!device) { 1226 LOG(WARNING) << "SetCarrierCallback with no cellular device."; 1227 return; 1228 } 1229 NetworkHandler::Get()->network_device_handler()->SetCarrier( 1230 device->path(), 1231 carrier, 1232 base::Bind(&InternetOptionsHandler::CarrierStatusCallback, 1233 weak_factory_.GetWeakPtr()), 1234 base::Bind(&ShillError, "SetCarrierCallback")); 1235} 1236 1237void InternetOptionsHandler::SetSimCardLockCallback( 1238 const base::ListValue* args) { 1239 bool require_pin_new_value; 1240 if (!args->GetBoolean(0, &require_pin_new_value)) { 1241 NOTREACHED(); 1242 return; 1243 } 1244 // 1. Bring up SIM unlock dialog, pass new RequirePin setting in URL. 1245 // 2. Dialog will ask for current PIN in any case. 1246 // 3. If card is locked it will first call PIN unlock operation 1247 // 4. Then it will call Set RequirePin, passing the same PIN. 1248 // 5. We'll get notified by REQUIRE_PIN_SETTING_CHANGE_ENDED notification. 1249 SimDialogDelegate::SimDialogMode mode; 1250 if (require_pin_new_value) 1251 mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON; 1252 else 1253 mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF; 1254 SimDialogDelegate::ShowDialog(GetNativeWindow(), mode); 1255} 1256 1257void InternetOptionsHandler::ChangePinCallback(const base::ListValue* args) { 1258 SimDialogDelegate::ShowDialog(GetNativeWindow(), 1259 SimDialogDelegate::SIM_DIALOG_CHANGE_PIN); 1260} 1261 1262void InternetOptionsHandler::RefreshNetworksCallback( 1263 const base::ListValue* args) { 1264 NetworkHandler::Get()->network_state_handler()->RequestScan(); 1265} 1266 1267std::string InternetOptionsHandler::GetIconDataUrl(int resource_id) const { 1268 gfx::ImageSkia* icon = 1269 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id); 1270 gfx::ImageSkiaRep image_rep = icon->GetRepresentation( 1271 ui::GetImageScale(web_ui()->GetDeviceScaleFactor())); 1272 return webui::GetBitmapDataUrl(image_rep.sk_bitmap()); 1273} 1274 1275void InternetOptionsHandler::RefreshNetworkData() { 1276 base::DictionaryValue dictionary; 1277 FillNetworkInfo(&dictionary); 1278 web_ui()->CallJavascriptFunction( 1279 kRefreshNetworkDataFunction, dictionary); 1280} 1281 1282void InternetOptionsHandler::UpdateConnectionData( 1283 const std::string& service_path) { 1284 NetworkHandler::Get()->network_configuration_handler()->GetProperties( 1285 service_path, 1286 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback, 1287 weak_factory_.GetWeakPtr()), 1288 base::Bind(&ShillError, "UpdateConnectionData")); 1289} 1290 1291void InternetOptionsHandler::UpdateConnectionDataCallback( 1292 const std::string& service_path, 1293 const base::DictionaryValue& shill_properties) { 1294 const NetworkState* network = GetNetworkState(service_path); 1295 if (!network) 1296 return; 1297 base::DictionaryValue dictionary; 1298 PopulateConnectionDetails(network, shill_properties, &dictionary); 1299 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, dictionary); 1300} 1301 1302void InternetOptionsHandler::UpdateCarrier() { 1303 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction); 1304} 1305 1306void InternetOptionsHandler::DeviceListChanged() { 1307 if (!web_ui()) 1308 return; 1309 RefreshNetworkData(); 1310} 1311 1312void InternetOptionsHandler::NetworkListChanged() { 1313 if (!web_ui()) 1314 return; 1315 RefreshNetworkData(); 1316} 1317 1318void InternetOptionsHandler::NetworkConnectionStateChanged( 1319 const NetworkState* network) { 1320 if (!web_ui()) 1321 return; 1322 // Update the connection data for the detailed view when the connection state 1323 // of any network changes. 1324 if (!details_path_.empty()) 1325 UpdateConnectionData(details_path_); 1326} 1327 1328void InternetOptionsHandler::NetworkPropertiesUpdated( 1329 const NetworkState* network) { 1330 if (!web_ui()) 1331 return; 1332 RefreshNetworkData(); 1333 UpdateConnectionData(network->path()); 1334} 1335 1336void InternetOptionsHandler::LoggedInStateChanged() { 1337 UpdateLoggedInUserType(); 1338} 1339 1340void InternetOptionsHandler::UpdateLoggedInUserType() { 1341 if (!web_ui()) 1342 return; 1343 base::StringValue login_type( 1344 LoggedInUserTypeToString(LoginState::Get()->GetLoggedInUserType())); 1345 web_ui()->CallJavascriptFunction( 1346 kUpdateLoggedInUserTypeFunction, login_type); 1347} 1348 1349void InternetOptionsHandler::Observe( 1350 int type, 1351 const content::NotificationSource& source, 1352 const content::NotificationDetails& details) { 1353 OptionsPageUIHandler::Observe(type, source, details); 1354 if (type == chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED) { 1355 base::FundamentalValue require_pin(*content::Details<bool>(details).ptr()); 1356 web_ui()->CallJavascriptFunction( 1357 kUpdateSecurityTabFunction, require_pin); 1358 } else if (type == chrome::NOTIFICATION_ENTER_PIN_ENDED) { 1359 // We make an assumption (which is valid for now) that the SIM 1360 // unlock dialog is put up only when the user is trying to enable 1361 // mobile data. 1362 bool cancelled = *content::Details<bool>(details).ptr(); 1363 if (cancelled) 1364 RefreshNetworkData(); 1365 // The case in which the correct PIN was entered and the SIM is 1366 // now unlocked is handled in NetworkMenuButton. 1367 } 1368} 1369 1370void InternetOptionsHandler::SetServerHostnameCallback( 1371 const base::ListValue* args) { 1372 std::string service_path, server_hostname; 1373 if (args->GetSize() < 2 || 1374 !args->GetString(0, &service_path) || 1375 !args->GetString(1, &server_hostname)) { 1376 NOTREACHED(); 1377 return; 1378 } 1379 SetNetworkProperty(service_path, shill::kProviderHostProperty, 1380 base::Value::CreateStringValue(server_hostname)); 1381} 1382 1383void InternetOptionsHandler::SetPreferNetworkCallback( 1384 const base::ListValue* args) { 1385 std::string service_path, prefer_network_str; 1386 if (args->GetSize() < 2 || 1387 !args->GetString(0, &service_path) || 1388 !args->GetString(1, &prefer_network_str)) { 1389 NOTREACHED(); 1390 return; 1391 } 1392 int priority = (prefer_network_str == kTagTrue) ? kPreferredPriority : 0; 1393 SetNetworkProperty(service_path, shill::kPriorityProperty, 1394 base::Value::CreateIntegerValue(priority)); 1395} 1396 1397void InternetOptionsHandler::SetAutoConnectCallback( 1398 const base::ListValue* args) { 1399 std::string service_path, auto_connect_str; 1400 if (args->GetSize() < 2 || 1401 !args->GetString(0, &service_path) || 1402 !args->GetString(1, &auto_connect_str)) { 1403 NOTREACHED(); 1404 return; 1405 } 1406 bool auto_connect = auto_connect_str == kTagTrue; 1407 SetNetworkProperty(service_path, shill::kAutoConnectProperty, 1408 base::Value::CreateBooleanValue(auto_connect)); 1409} 1410 1411void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) { 1412 std::string service_path; 1413 if (!args->GetString(0, &service_path)) { 1414 NOTREACHED(); 1415 return; 1416 } 1417 NetworkHandler::Get()->network_configuration_handler()->GetProperties( 1418 service_path, 1419 base::Bind(&InternetOptionsHandler::SetIPConfigProperties, 1420 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())), 1421 base::Bind(&ShillError, "SetIPConfigCallback")); 1422} 1423 1424void InternetOptionsHandler::SetIPConfigProperties( 1425 const base::ListValue* args, 1426 const std::string& service_path, 1427 const base::DictionaryValue& shill_properties) { 1428 std::string address, netmask, gateway, name_server_type, name_servers; 1429 bool dhcp_for_ip; 1430 if (!args->GetBoolean(1, &dhcp_for_ip) || 1431 !args->GetString(2, &address) || 1432 !args->GetString(3, &netmask) || 1433 !args->GetString(4, &gateway) || 1434 !args->GetString(5, &name_server_type) || 1435 !args->GetString(6, &name_servers)) { 1436 NOTREACHED(); 1437 return; 1438 } 1439 NET_LOG_USER("SetIPConfigProperties", service_path); 1440 1441 bool request_reconnect = false; 1442 std::vector<std::string> properties_to_clear; 1443 base::DictionaryValue properties_to_set; 1444 1445 if (dhcp_for_ip) { 1446 request_reconnect |= AppendPropertyKeyIfPresent( 1447 shill::kStaticIPAddressProperty, 1448 shill_properties, &properties_to_clear); 1449 request_reconnect |= AppendPropertyKeyIfPresent( 1450 shill::kStaticIPPrefixlenProperty, 1451 shill_properties, &properties_to_clear); 1452 request_reconnect |= AppendPropertyKeyIfPresent( 1453 shill::kStaticIPGatewayProperty, 1454 shill_properties, &properties_to_clear); 1455 } else { 1456 request_reconnect |= AddStringPropertyIfChanged( 1457 shill::kStaticIPAddressProperty, 1458 address, shill_properties, &properties_to_set); 1459 int prefixlen = network_util::NetmaskToPrefixLength(netmask); 1460 if (prefixlen > 0) { 1461 LOG(ERROR) << "Invalid prefix length for: " << service_path; 1462 prefixlen = 0; 1463 } 1464 request_reconnect |= AddIntegerPropertyIfChanged( 1465 shill::kStaticIPPrefixlenProperty, 1466 prefixlen, shill_properties, &properties_to_set); 1467 request_reconnect |= AddStringPropertyIfChanged( 1468 shill::kStaticIPGatewayProperty, 1469 gateway, shill_properties, &properties_to_set); 1470 } 1471 1472 if (name_server_type == kNameServerTypeAutomatic) { 1473 AppendPropertyKeyIfPresent(shill::kStaticIPNameServersProperty, 1474 shill_properties, &properties_to_clear); 1475 } else { 1476 if (name_server_type == kNameServerTypeGoogle) 1477 name_servers = kGoogleNameServers; 1478 AddStringPropertyIfChanged( 1479 shill::kStaticIPNameServersProperty, 1480 name_servers, shill_properties, &properties_to_set); 1481 } 1482 1483 if (!properties_to_clear.empty()) { 1484 NetworkHandler::Get()->network_configuration_handler()->ClearProperties( 1485 service_path, properties_to_clear, 1486 base::Bind(&base::DoNothing), 1487 base::Bind(&ShillError, "ClearIPConfigProperties")); 1488 } 1489 if (!properties_to_set.empty()) { 1490 NetworkHandler::Get()->network_configuration_handler()->SetProperties( 1491 service_path, properties_to_set, 1492 base::Bind(&base::DoNothing), 1493 base::Bind(&ShillError, "SetIPConfigProperties")); 1494 } 1495 std::string device_path; 1496 shill_properties.GetStringWithoutPathExpansion( 1497 shill::kDeviceProperty, &device_path); 1498 if (!device_path.empty()) { 1499 base::Closure callback = base::Bind(&base::DoNothing); 1500 // If auto config or a static IP property changed, we need to reconnect 1501 // to the network. 1502 if (request_reconnect) 1503 callback = base::Bind(&RequestReconnect, service_path, GetNativeWindow()); 1504 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs( 1505 device_path, 1506 callback, 1507 base::Bind(&ShillError, "RequestRefreshIPConfigs")); 1508 } 1509} 1510 1511void InternetOptionsHandler::PopulateDictionaryDetailsCallback( 1512 const std::string& service_path, 1513 const base::DictionaryValue& shill_properties) { 1514 const NetworkState* network = GetNetworkState(service_path); 1515 if (!network) { 1516 LOG(ERROR) << "Network properties not found: " << service_path; 1517 return; 1518 } 1519 1520 details_path_ = service_path; 1521 1522 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE; 1523 const base::DictionaryValue* onc = 1524 onc::FindPolicyForActiveUser(network->guid(), &onc_source); 1525 const NetworkPropertyUIData property_ui_data(onc_source); 1526 1527 base::DictionaryValue dictionary; 1528 1529 // Device hardware address 1530 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> 1531 GetDeviceState(network->device_path()); 1532 if (device) 1533 dictionary.SetString(kTagHardwareAddress, device->mac_address()); 1534 1535 // IP config 1536 scoped_ptr<base::DictionaryValue> ipconfig_dhcp(new base::DictionaryValue); 1537 ipconfig_dhcp->SetString(kIpConfigAddress, network->ip_address()); 1538 ipconfig_dhcp->SetString(kIpConfigNetmask, network->GetNetmask()); 1539 ipconfig_dhcp->SetString(kIpConfigGateway, network->gateway()); 1540 std::string ipconfig_name_servers = network->GetDnsServersAsString(); 1541 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers); 1542 ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl, 1543 network->web_proxy_auto_discovery_url().spec()); 1544 SetValueDictionary(&dictionary, 1545 kDictionaryIpConfig, 1546 ipconfig_dhcp.release(), 1547 property_ui_data); 1548 1549 std::string name_server_type = kNameServerTypeAutomatic; 1550 int automatic_ip_config = 0; 1551 scoped_ptr<base::DictionaryValue> static_ip_dict( 1552 BuildIPInfoDictionary(shill_properties, true, &automatic_ip_config)); 1553 dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0); 1554 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0) 1555 << "UI doesn't support automatic specification of individual " 1556 << "static IP parameters."; 1557 scoped_ptr<base::DictionaryValue> saved_ip_dict( 1558 BuildIPInfoDictionary(shill_properties, false, NULL)); 1559 dictionary.Set(kDictionarySavedIp, saved_ip_dict.release()); 1560 1561 // Determine what kind of name server setting we have by comparing the 1562 // StaticIP and Google values with the ipconfig values. 1563 std::string static_ip_nameservers; 1564 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers); 1565 if (!static_ip_nameservers.empty() && 1566 static_ip_nameservers == ipconfig_name_servers) { 1567 name_server_type = kNameServerTypeUser; 1568 } 1569 if (ipconfig_name_servers == kGoogleNameServers) { 1570 name_server_type = kNameServerTypeGoogle; 1571 } 1572 SetValueDictionary(&dictionary, 1573 kDictionaryStaticIp, 1574 static_ip_dict.release(), 1575 property_ui_data); 1576 1577 std::string type = network->type(); 1578 dictionary.SetString(kTagType, type); 1579 dictionary.SetString(kTagServicePath, network->path()); 1580 dictionary.SetString(kTagNameServerType, name_server_type); 1581 dictionary.SetString(kTagNameServersGoogle, kGoogleNameServers); 1582 1583 // Only show proxy for remembered networks. 1584 dictionary.SetBoolean(kTagShowProxy, !network->profile_path().empty()); 1585 1586 // Enable static ip config for Ethernet or WiFi. 1587 bool staticIPConfig = network->Matches(NetworkTypePattern::Ethernet()) || 1588 type == shill::kTypeWifi; 1589 dictionary.SetBoolean(kTagShowStaticIPConfig, staticIPConfig); 1590 1591 dictionary.SetBoolean(kTagShowPreferred, !network->profile_path().empty()); 1592 int priority = 0; 1593 shill_properties.GetIntegerWithoutPathExpansion( 1594 shill::kPriorityProperty, &priority); 1595 bool preferred = priority > 0; 1596 SetValueDictionary(&dictionary, kTagPreferred, 1597 new base::FundamentalValue(preferred), 1598 property_ui_data); 1599 1600 NetworkPropertyUIData auto_connect_ui_data(onc_source); 1601 std::string onc_path_to_auto_connect; 1602 if (type == shill::kTypeWifi) { 1603 onc_path_to_auto_connect = base::StringPrintf( 1604 "%s.%s", 1605 ::onc::network_config::kWiFi, 1606 ::onc::wifi::kAutoConnect); 1607 } else if (type == shill::kTypeVPN) { 1608 onc_path_to_auto_connect = base::StringPrintf( 1609 "%s.%s", 1610 ::onc::network_config::kVPN, 1611 ::onc::vpn::kAutoConnect); 1612 } 1613 if (!onc_path_to_auto_connect.empty()) { 1614 auto_connect_ui_data.ParseOncProperty( 1615 onc_source, onc, onc_path_to_auto_connect); 1616 } 1617 bool auto_connect = false; 1618 shill_properties.GetBooleanWithoutPathExpansion( 1619 shill::kAutoConnectProperty, &auto_connect); 1620 SetAutoconnectValueDictionary(network->IsPrivate(), 1621 onc_source, 1622 auto_connect, 1623 auto_connect_ui_data, 1624 &dictionary); 1625 1626 PopulateConnectionDetails(network, shill_properties, &dictionary); 1627 1628 // Show details dialog 1629 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, dictionary); 1630} 1631 1632namespace { 1633 1634void PopulateConnectionDetails(const NetworkState* network, 1635 const base::DictionaryValue& shill_properties, 1636 base::DictionaryValue* dictionary) { 1637 dictionary->SetString(kNetworkInfoKeyServicePath, network->path()); 1638 dictionary->SetString(kTagServiceName, network->name()); 1639 dictionary->SetBoolean(kTagConnecting, network->IsConnectingState()); 1640 dictionary->SetBoolean(kTagConnected, network->IsConnectedState()); 1641 dictionary->SetString(kTagConnectionState, 1642 ConnectionStateString(network->connection_state())); 1643 dictionary->SetString(kTagNetworkName, network->name()); 1644 dictionary->SetString( 1645 kTagErrorState, 1646 ash::network_connect::ErrorString(network->error(), network->path())); 1647 1648 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty()); 1649 bool shared = !network->IsPrivate(); 1650 dictionary->SetBoolean(kTagShared, shared); 1651 1652 const std::string& type = network->type(); 1653 const NetworkState* connected_network = 1654 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( 1655 NetworkTypePattern::Primitive(type)); 1656 1657 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); 1658 1659 if (type == shill::kTypeWifi) 1660 PopulateWifiDetails(network, shill_properties, dictionary); 1661 else if (type == shill::kTypeWimax) 1662 PopulateWimaxDetails(network, shill_properties, dictionary); 1663 else if (type == shill::kTypeCellular) 1664 PopulateCellularDetails(network, shill_properties, dictionary); 1665 else if (type == shill::kTypeVPN) 1666 PopulateVPNDetails(network, shill_properties, dictionary); 1667} 1668 1669void PopulateWifiDetails(const NetworkState* wifi, 1670 const base::DictionaryValue& shill_properties, 1671 base::DictionaryValue* dictionary) { 1672 dictionary->SetString(kTagSsid, wifi->name()); 1673 dictionary->SetInteger(kTagStrength, wifi->signal_strength()); 1674 dictionary->SetString(kTagEncryption, 1675 EncryptionString(wifi->security(), wifi->eap_method())); 1676 CopyStringFromDictionary(shill_properties, shill::kWifiBSsid, 1677 kTagBssid, dictionary); 1678 CopyIntegerFromDictionary(shill_properties, shill::kWifiFrequency, 1679 kTagFrequency, false, dictionary); 1680} 1681 1682void PopulateWimaxDetails(const NetworkState* wimax, 1683 const base::DictionaryValue& shill_properties, 1684 base::DictionaryValue* dictionary) { 1685 dictionary->SetInteger(kTagStrength, wimax->signal_strength()); 1686 CopyStringFromDictionary(shill_properties, shill::kEapIdentityProperty, 1687 kTagIdentity, dictionary); 1688} 1689 1690void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn, 1691 base::DictionaryValue* dictionary) { 1692 CopyStringFromDictionary(*apn, shill::kApnProperty, 1693 kTagApn, dictionary); 1694 CopyStringFromDictionary(*apn, shill::kApnNetworkIdProperty, 1695 kTagNetworkId, dictionary); 1696 CopyStringFromDictionary(*apn, shill::kApnUsernameProperty, 1697 kTagUsername, dictionary); 1698 CopyStringFromDictionary(*apn, shill::kApnPasswordProperty, 1699 kTagPassword, dictionary); 1700 CopyStringFromDictionary(*apn, shill::kApnNameProperty, 1701 kTagName, dictionary); 1702 CopyStringFromDictionary(*apn, shill::kApnLocalizedNameProperty, 1703 kTagLocalizedName, dictionary); 1704 CopyStringFromDictionary(*apn, shill::kApnLanguageProperty, 1705 kTagLanguage, dictionary); 1706} 1707 1708void PopulateCellularDetails(const NetworkState* cellular, 1709 const base::DictionaryValue& shill_properties, 1710 base::DictionaryValue* dictionary) { 1711 dictionary->SetBoolean(kTagCarrierSelectFlag, 1712 CommandLine::ForCurrentProcess()->HasSwitch( 1713 chromeos::switches::kEnableCarrierSwitching)); 1714 // Cellular network / connection settings. 1715 dictionary->SetString(kTagNetworkTechnology, cellular->network_technology()); 1716 dictionary->SetString(kTagActivationState, 1717 ActivationStateString(cellular->activation_state())); 1718 dictionary->SetString(kTagRoamingState, 1719 RoamingStateString(cellular->roaming())); 1720 bool restricted = cellular->connection_state() == shill::kStatePortal; 1721 dictionary->SetString(kTagRestrictedPool, 1722 restricted ? 1723 l10n_util::GetStringUTF8( 1724 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) : 1725 l10n_util::GetStringUTF8( 1726 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); 1727 1728 const base::DictionaryValue* serving_operator = NULL; 1729 if (shill_properties.GetDictionaryWithoutPathExpansion( 1730 shill::kServingOperatorProperty, &serving_operator)) { 1731 CopyStringFromDictionary(*serving_operator, shill::kOperatorNameKey, 1732 kTagOperatorName, dictionary); 1733 CopyStringFromDictionary(*serving_operator, shill::kOperatorCodeKey, 1734 kTagOperatorCode, dictionary); 1735 } 1736 1737 const base::DictionaryValue* olp = NULL; 1738 if (shill_properties.GetDictionaryWithoutPathExpansion( 1739 shill::kPaymentPortalProperty, &olp)) { 1740 std::string url; 1741 olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url); 1742 dictionary->SetString(kTagSupportUrl, url); 1743 } 1744 1745 base::DictionaryValue* apn = new base::DictionaryValue; 1746 const base::DictionaryValue* source_apn = NULL; 1747 if (shill_properties.GetDictionaryWithoutPathExpansion( 1748 shill::kCellularApnProperty, &source_apn)) { 1749 CreateDictionaryFromCellularApn(source_apn, apn); 1750 } 1751 dictionary->Set(kTagApn, apn); 1752 1753 base::DictionaryValue* last_good_apn = new base::DictionaryValue; 1754 if (shill_properties.GetDictionaryWithoutPathExpansion( 1755 shill::kCellularLastGoodApnProperty, &source_apn)) { 1756 CreateDictionaryFromCellularApn(source_apn, last_good_apn); 1757 } 1758 dictionary->Set(kTagLastGoodApn, last_good_apn); 1759 1760 // These default to empty and are only set if device != NULL. 1761 std::string carrier_id; 1762 std::string mdn; 1763 1764 // Device settings. 1765 const DeviceState* device = NetworkHandler::Get()->network_state_handler()-> 1766 GetDeviceState(cellular->device_path()); 1767 if (device) { 1768 // TODO(stevenjb): Add NetworkDeviceHandler::GetProperties() and use that 1769 // to retrieve the complete dictionary of device properties, instead of 1770 // caching them (will be done for the new UI). 1771 const base::DictionaryValue& device_properties = device->properties(); 1772 const NetworkPropertyUIData cellular_property_ui_data( 1773 cellular->ui_data().onc_source()); 1774 CopyStringFromDictionary(device_properties, shill::kManufacturerProperty, 1775 kTagManufacturer, dictionary); 1776 CopyStringFromDictionary(device_properties, shill::kModelIDProperty, 1777 kTagModelId, dictionary); 1778 CopyStringFromDictionary(device_properties, 1779 shill::kFirmwareRevisionProperty, 1780 kTagFirmwareRevision, dictionary); 1781 CopyStringFromDictionary(device_properties, 1782 shill::kHardwareRevisionProperty, 1783 kTagHardwareRevision, dictionary); 1784 CopyIntegerFromDictionary(device_properties, shill::kPRLVersionProperty, 1785 kTagPrlVersion, true, dictionary); 1786 CopyStringFromDictionary(device_properties, shill::kMeidProperty, 1787 kTagMeid, dictionary); 1788 CopyStringFromDictionary(device_properties, shill::kIccidProperty, 1789 kTagIccid, dictionary); 1790 CopyStringFromDictionary(device_properties, shill::kImeiProperty, 1791 kTagImei, dictionary); 1792 mdn = CopyStringFromDictionary(device_properties, shill::kMdnProperty, 1793 kTagMdn, dictionary); 1794 CopyStringFromDictionary(device_properties, shill::kImsiProperty, 1795 kTagImsi, dictionary); 1796 CopyStringFromDictionary(device_properties, shill::kEsnProperty, 1797 kTagEsn, dictionary); 1798 CopyStringFromDictionary(device_properties, shill::kMinProperty, 1799 kTagMin, dictionary); 1800 std::string family; 1801 device_properties.GetStringWithoutPathExpansion( 1802 shill::kTechnologyFamilyProperty, &family); 1803 dictionary->SetBoolean(kTagGsm, family == shill::kNetworkTechnologyGsm); 1804 1805 SetValueDictionary( 1806 dictionary, kTagSimCardLockEnabled, 1807 new base::FundamentalValue(device->sim_lock_enabled()), 1808 cellular_property_ui_data); 1809 1810 carrier_id = device->home_provider_id(); 1811 1812 MobileConfig* config = MobileConfig::GetInstance(); 1813 if (config->IsReady()) { 1814 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id); 1815 if (carrier && !carrier->top_up_url().empty()) 1816 dictionary->SetString(kTagCarrierUrl, carrier->top_up_url()); 1817 } 1818 1819 base::ListValue* apn_list_value = new base::ListValue(); 1820 const base::ListValue* apn_list; 1821 if (device_properties.GetListWithoutPathExpansion( 1822 shill::kCellularApnListProperty, &apn_list)) { 1823 for (base::ListValue::const_iterator iter = apn_list->begin(); 1824 iter != apn_list->end(); ++iter) { 1825 const base::DictionaryValue* dict; 1826 if ((*iter)->GetAsDictionary(&dict)) { 1827 base::DictionaryValue* apn = new base::DictionaryValue; 1828 CreateDictionaryFromCellularApn(dict, apn); 1829 apn_list_value->Append(apn); 1830 } 1831 } 1832 } 1833 SetValueDictionary(dictionary, kTagProviderApnList, apn_list_value, 1834 cellular_property_ui_data); 1835 if (CommandLine::ForCurrentProcess()->HasSwitch( 1836 chromeos::switches::kEnableCarrierSwitching)) { 1837 const base::ListValue* supported_carriers; 1838 if (device_properties.GetListWithoutPathExpansion( 1839 shill::kSupportedCarriersProperty, &supported_carriers)) { 1840 dictionary->Set(kTagCarriers, supported_carriers->DeepCopy()); 1841 dictionary->SetInteger(kTagCurrentCarrierIndex, 1842 FindCurrentCarrierIndex(supported_carriers, 1843 device)); 1844 } else { 1845 // In case of any error, set the current carrier tag to -1 indicating 1846 // to the JS code to fallback to a single carrier. 1847 dictionary->SetInteger(kTagCurrentCarrierIndex, -1); 1848 } 1849 } 1850 } 1851 1852 // Set Cellular Buttons Visibility 1853 dictionary->SetBoolean( 1854 kTagDisableConnectButton, 1855 cellular->activation_state() == shill::kActivationStateActivating || 1856 cellular->IsConnectingState()); 1857 1858 // Don't show any account management related buttons if the activation 1859 // state is unknown or no payment portal URL is available. 1860 std::string support_url; 1861 if (cellular->activation_state() == shill::kActivationStateUnknown || 1862 !dictionary->GetString(kTagSupportUrl, &support_url) || 1863 support_url.empty()) { 1864 VLOG(2) << "No support URL is available. Don't display buttons."; 1865 return; 1866 } 1867 1868 if (cellular->activation_state() != shill::kActivationStateActivating && 1869 cellular->activation_state() != shill::kActivationStateActivated) { 1870 dictionary->SetBoolean(kTagShowActivateButton, true); 1871 } else { 1872 const MobileConfig::Carrier* carrier = 1873 MobileConfig::GetInstance()->GetCarrier(carrier_id); 1874 if (carrier && carrier->show_portal_button()) { 1875 // The button should be shown for a LTE network even when the LTE network 1876 // is not connected, but CrOS is online. This is done to enable users to 1877 // update their plan even if they are out of credits. 1878 // The button should not be shown when the device's mdn is not set, 1879 // because the network's proper portal url cannot be generated without it 1880 const NetworkState* default_network = 1881 NetworkHandler::Get()->network_state_handler()->DefaultNetwork(); 1882 const std::string& technology = cellular->network_technology(); 1883 bool force_show_view_account_button = 1884 (technology == shill::kNetworkTechnologyLte || 1885 technology == shill::kNetworkTechnologyLteAdvanced) && 1886 default_network && 1887 !mdn.empty(); 1888 1889 // The button will trigger ShowMorePlanInfoCallback() which will open 1890 // carrier specific portal. 1891 if (cellular->IsConnectedState() || force_show_view_account_button) 1892 dictionary->SetBoolean(kTagShowViewAccountButton, true); 1893 } 1894 } 1895} 1896 1897} // namespace 1898 1899gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { 1900 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow(); 1901} 1902 1903Browser* InternetOptionsHandler::GetAppropriateBrowser() { 1904 return chrome::FindOrCreateTabbedBrowser( 1905 ProfileManager::GetDefaultProfileOrOffTheRecord(), 1906 chrome::HOST_DESKTOP_TYPE_ASH); 1907} 1908 1909void InternetOptionsHandler::NetworkCommandCallback( 1910 const base::ListValue* args) { 1911 std::string type; 1912 std::string service_path; 1913 std::string command; 1914 if (args->GetSize() != 3 || 1915 !args->GetString(0, &type) || 1916 !args->GetString(1, &service_path) || 1917 !args->GetString(2, &command)) { 1918 NOTREACHED(); 1919 return; 1920 } 1921 1922 // Process commands that do not require an existing network. 1923 if (command == kTagAddConnection) { 1924 if (CanAddNetworkType(type)) 1925 AddConnection(type); 1926 } else if (command == kTagForget) { 1927 if (CanForgetNetworkType(type)) { 1928 NetworkHandler::Get()->network_configuration_handler()-> 1929 RemoveConfiguration( 1930 service_path, 1931 base::Bind(&base::DoNothing), 1932 base::Bind(&ShillError, "NetworkCommand: " + command)); 1933 } 1934 } else if (command == kTagOptions) { 1935 NetworkHandler::Get()->network_configuration_handler()->GetProperties( 1936 service_path, 1937 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, 1938 weak_factory_.GetWeakPtr()), 1939 base::Bind(&ShillError, "NetworkCommand: " + command)); 1940 } else if (command == kTagConnect) { 1941 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow()); 1942 } else if (command == kTagDisconnect) { 1943 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork( 1944 service_path, 1945 base::Bind(&base::DoNothing), 1946 base::Bind(&ShillError, "NetworkCommand: " + command)); 1947 } else if (command == kTagConfigure) { 1948 NetworkConfigView::Show(service_path, GetNativeWindow()); 1949 } else if (command == kTagActivate && type == shill::kTypeCellular) { 1950 ash::network_connect::ActivateCellular(service_path); 1951 // Activation may update network properties (e.g. ActivationState), so 1952 // request them here in case they change. 1953 UpdateConnectionData(service_path); 1954 } else { 1955 VLOG(1) << "Unknown command: " << command; 1956 NOTREACHED(); 1957 } 1958} 1959 1960void InternetOptionsHandler::AddConnection(const std::string& type) { 1961 if (type == shill::kTypeWifi) 1962 NetworkConfigView::ShowForType(shill::kTypeWifi, GetNativeWindow()); 1963 else if (type == shill::kTypeVPN) 1964 NetworkConfigView::ShowForType(shill::kTypeVPN, GetNativeWindow()); 1965 else if (type == shill::kTypeCellular) 1966 ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow()); 1967 else 1968 NOTREACHED(); 1969} 1970 1971base::ListValue* InternetOptionsHandler::GetWiredList() { 1972 base::ListValue* list = new base::ListValue(); 1973 const NetworkState* network = NetworkHandler::Get()->network_state_handler()-> 1974 FirstNetworkByType(NetworkTypePattern::Ethernet()); 1975 if (!network) 1976 return list; 1977 list->Append( 1978 BuildNetworkDictionary(network, 1979 web_ui()->GetDeviceScaleFactor(), 1980 Profile::FromWebUI(web_ui())->GetPrefs())); 1981 return list; 1982} 1983 1984base::ListValue* InternetOptionsHandler::GetWirelessList() { 1985 base::ListValue* list = new base::ListValue(); 1986 1987 NetworkStateHandler::NetworkStateList networks; 1988 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 1989 NetworkTypePattern::Wireless(), &networks); 1990 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 1991 networks.begin(); iter != networks.end(); ++iter) { 1992 list->Append( 1993 BuildNetworkDictionary(*iter, 1994 web_ui()->GetDeviceScaleFactor(), 1995 Profile::FromWebUI(web_ui())->GetPrefs())); 1996 } 1997 1998 return list; 1999} 2000 2001base::ListValue* InternetOptionsHandler::GetVPNList() { 2002 base::ListValue* list = new base::ListValue(); 2003 2004 NetworkStateHandler::NetworkStateList networks; 2005 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType( 2006 NetworkTypePattern::VPN(), &networks); 2007 for (NetworkStateHandler::NetworkStateList::const_iterator iter = 2008 networks.begin(); iter != networks.end(); ++iter) { 2009 list->Append( 2010 BuildNetworkDictionary(*iter, 2011 web_ui()->GetDeviceScaleFactor(), 2012 Profile::FromWebUI(web_ui())->GetPrefs())); 2013 } 2014 2015 return list; 2016} 2017 2018base::ListValue* InternetOptionsHandler::GetRememberedList() { 2019 base::ListValue* list = new base::ListValue(); 2020 2021 NetworkStateHandler::FavoriteStateList favorites; 2022 NetworkHandler::Get()->network_state_handler()->GetFavoriteList(&favorites); 2023 for (NetworkStateHandler::FavoriteStateList::const_iterator iter = 2024 favorites.begin(); iter != favorites.end(); ++iter) { 2025 const FavoriteState* favorite = *iter; 2026 if (favorite->type() != shill::kTypeWifi && 2027 favorite->type() != shill::kTypeVPN) 2028 continue; 2029 list->Append( 2030 BuildFavoriteDictionary(favorite, 2031 web_ui()->GetDeviceScaleFactor(), 2032 Profile::FromWebUI(web_ui())->GetPrefs())); 2033 } 2034 2035 return list; 2036} 2037 2038void InternetOptionsHandler::FillNetworkInfo( 2039 base::DictionaryValue* dictionary) { 2040 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 2041 dictionary->Set(kTagWiredList, GetWiredList()); 2042 dictionary->Set(kTagWirelessList, GetWirelessList()); 2043 dictionary->Set(kTagVpnList, GetVPNList()); 2044 dictionary->Set(kTagRememberedList, GetRememberedList()); 2045 2046 dictionary->SetBoolean( 2047 kTagWifiAvailable, 2048 handler->IsTechnologyAvailable(NetworkTypePattern::WiFi())); 2049 dictionary->SetBoolean( 2050 kTagWifiEnabled, 2051 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi())); 2052 2053 dictionary->SetBoolean( 2054 kTagCellularAvailable, 2055 handler->IsTechnologyAvailable(NetworkTypePattern::Mobile())); 2056 dictionary->SetBoolean( 2057 kTagCellularEnabled, 2058 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile())); 2059 const DeviceState* cellular = 2060 handler->GetDeviceStateByType(NetworkTypePattern::Mobile()); 2061 dictionary->SetBoolean( 2062 kTagCellularSupportsScan, 2063 cellular && cellular->support_network_scan()); 2064 2065 dictionary->SetBoolean( 2066 kTagWimaxAvailable, 2067 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); 2068 dictionary->SetBoolean( 2069 kTagWimaxEnabled, 2070 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); 2071} 2072 2073} // namespace options 2074} // namespace chromeos 2075