OLD | NEW |
(Empty) | |
| 1 // Copyright (c) 2011 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/options2/chromeos/internet_options_handler.h" |
| 6 |
| 7 #include <ctype.h> |
| 8 |
| 9 #include <map> |
| 10 #include <string> |
| 11 #include <vector> |
| 12 |
| 13 #include "base/base64.h" |
| 14 #include "base/basictypes.h" |
| 15 #include "base/bind.h" |
| 16 #include "base/bind_helpers.h" |
| 17 #include "base/command_line.h" |
| 18 #include "base/i18n/time_formatting.h" |
| 19 #include "base/string16.h" |
| 20 #include "base/string_number_conversions.h" |
| 21 #include "base/stringprintf.h" |
| 22 #include "base/time.h" |
| 23 #include "base/utf_string_conversions.h" |
| 24 #include "base/values.h" |
| 25 #include "chrome/browser/browser_process.h" |
| 26 #include "chrome/browser/chromeos/choose_mobile_network_dialog.h" |
| 27 #include "chrome/browser/chromeos/cros/cros_library.h" |
| 28 #include "chrome/browser/chromeos/cros/network_library.h" |
| 29 #include "chrome/browser/chromeos/cros_settings.h" |
| 30 #include "chrome/browser/chromeos/mobile_config.h" |
| 31 #include "chrome/browser/chromeos/options/network_config_view.h" |
| 32 #include "chrome/browser/chromeos/proxy_config_service_impl.h" |
| 33 #include "chrome/browser/chromeos/sim_dialog_delegate.h" |
| 34 #include "chrome/browser/chromeos/status/network_menu_icon.h" |
| 35 #include "chrome/browser/net/pref_proxy_config_tracker.h" |
| 36 #include "chrome/browser/profiles/profile.h" |
| 37 #include "chrome/browser/ui/browser.h" |
| 38 #include "chrome/browser/ui/browser_list.h" |
| 39 #include "chrome/browser/ui/browser_window.h" |
| 40 #include "chrome/browser/ui/dialog_style.h" |
| 41 #include "chrome/browser/ui/views/window.h" |
| 42 #include "chrome/browser/ui/webui/web_ui_util.h" |
| 43 #include "chrome/common/chrome_notification_types.h" |
| 44 #include "chrome/common/chrome_switches.h" |
| 45 #include "chrome/common/time_format.h" |
| 46 #include "content/public/browser/notification_service.h" |
| 47 #include "grit/chromium_strings.h" |
| 48 #include "grit/generated_resources.h" |
| 49 #include "grit/locale_settings.h" |
| 50 #include "grit/theme_resources.h" |
| 51 #include "third_party/skia/include/core/SkBitmap.h" |
| 52 #include "ui/base/l10n/l10n_util.h" |
| 53 #include "ui/base/resource/resource_bundle.h" |
| 54 #include "ui/views/widget/widget.h" |
| 55 |
| 56 namespace { |
| 57 |
| 58 static const char kOtherNetworksFakePath[] = "?"; |
| 59 |
| 60 // Keys for the network description dictionary passed to the web ui. Make sure |
| 61 // to keep the strings in sync with what the Javascript side uses. |
| 62 const char kNetworkInfoKeyActivationState[] = "activation_state"; |
| 63 const char kNetworkInfoKeyConnectable[] = "connectable"; |
| 64 const char kNetworkInfoKeyConnected[] = "connected"; |
| 65 const char kNetworkInfoKeyConnecting[] = "connecting"; |
| 66 const char kNetworkInfoKeyIconURL[] = "iconURL"; |
| 67 const char kNetworkInfoKeyNeedsNewPlan[] = "needs_new_plan"; |
| 68 const char kNetworkInfoKeyNetworkName[] = "networkName"; |
| 69 const char kNetworkInfoKeyNetworkStatus[] = "networkStatus"; |
| 70 const char kNetworkInfoKeyNetworkType[] = "networkType"; |
| 71 const char kNetworkInfoKeyRemembered[] = "remembered"; |
| 72 const char kNetworkInfoKeyServicePath[] = "servicePath"; |
| 73 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; |
| 74 |
| 75 // A helper class for building network information dictionaries to be sent to |
| 76 // the webui code. |
| 77 class NetworkInfoDictionary { |
| 78 public: |
| 79 // Initializes the dictionary with default values. |
| 80 NetworkInfoDictionary(); |
| 81 |
| 82 // Copies in service path, connect{ing|ed|able} flags and connection type from |
| 83 // the provided network object. Also chooses an appropriate icon based on the |
| 84 // network type. |
| 85 explicit NetworkInfoDictionary(const chromeos::Network* network); |
| 86 |
| 87 // Initializes a remembered network entry, pulling information from the passed |
| 88 // network object and the corresponding remembered network object. |network| |
| 89 // may be NULL. |
| 90 NetworkInfoDictionary(const chromeos::Network* network, |
| 91 const chromeos::Network* remembered); |
| 92 |
| 93 // Setters for filling in information. |
| 94 void set_service_path(const std::string& service_path) { |
| 95 service_path_ = service_path; |
| 96 } |
| 97 void set_icon(const SkBitmap& icon) { |
| 98 icon_url_ = icon.isNull() ? "" : web_ui_util::GetImageDataUrl(icon); |
| 99 } |
| 100 void set_name(const std::string& name) { |
| 101 name_ = name; |
| 102 } |
| 103 void set_connecting(bool connecting) { |
| 104 connecting_ = connecting; |
| 105 } |
| 106 void set_connected(bool connected) { |
| 107 connected_ = connected; |
| 108 } |
| 109 void set_connectable(bool connectable) { |
| 110 connectable_ = connectable; |
| 111 } |
| 112 void set_connection_type(chromeos::ConnectionType connection_type) { |
| 113 connection_type_ = connection_type; |
| 114 } |
| 115 void set_remembered(bool remembered) { |
| 116 remembered_ = remembered; |
| 117 } |
| 118 void set_shared(bool shared) { |
| 119 shared_ = shared; |
| 120 } |
| 121 void set_activation_state(chromeos::ActivationState activation_state) { |
| 122 activation_state_ = activation_state; |
| 123 } |
| 124 void set_needs_new_plan(bool needs_new_plan) { |
| 125 needs_new_plan_ = needs_new_plan; |
| 126 } |
| 127 void set_policy_managed(bool policy_managed) { |
| 128 policy_managed_ = policy_managed; |
| 129 } |
| 130 |
| 131 // Builds the DictionaryValue representation from the previously set |
| 132 // parameters. Ownership of the returned pointer is transferred to the caller. |
| 133 DictionaryValue* BuildDictionary(); |
| 134 |
| 135 private: |
| 136 // Values to be filled into the dictionary. |
| 137 std::string service_path_; |
| 138 std::string icon_url_; |
| 139 std::string name_; |
| 140 bool connecting_; |
| 141 bool connected_; |
| 142 bool connectable_; |
| 143 chromeos::ConnectionType connection_type_; |
| 144 bool remembered_; |
| 145 bool shared_; |
| 146 chromeos::ActivationState activation_state_; |
| 147 bool needs_new_plan_; |
| 148 bool policy_managed_; |
| 149 |
| 150 DISALLOW_COPY_AND_ASSIGN(NetworkInfoDictionary); |
| 151 }; |
| 152 |
| 153 NetworkInfoDictionary::NetworkInfoDictionary() { |
| 154 set_connecting(false); |
| 155 set_connected(false); |
| 156 set_connectable(false); |
| 157 set_remembered(false); |
| 158 set_shared(false); |
| 159 set_activation_state(chromeos::ACTIVATION_STATE_UNKNOWN); |
| 160 set_needs_new_plan(false); |
| 161 set_policy_managed(false); |
| 162 } |
| 163 |
| 164 NetworkInfoDictionary::NetworkInfoDictionary(const chromeos::Network* network) { |
| 165 set_service_path(network->service_path()); |
| 166 set_icon(chromeos::NetworkMenuIcon::GetBitmap(network)); |
| 167 set_name(network->name()); |
| 168 set_connecting(network->connecting()); |
| 169 set_connected(network->connected()); |
| 170 set_connectable(network->connectable()); |
| 171 set_connection_type(network->type()); |
| 172 set_remembered(false); |
| 173 set_shared(false); |
| 174 set_needs_new_plan(false); |
| 175 set_policy_managed(chromeos::NetworkUIData::IsManaged(network)); |
| 176 } |
| 177 |
| 178 NetworkInfoDictionary::NetworkInfoDictionary( |
| 179 const chromeos::Network* network, |
| 180 const chromeos::Network* remembered) { |
| 181 set_service_path(remembered->service_path()); |
| 182 set_icon( |
| 183 chromeos::NetworkMenuIcon::GetBitmap(network ? network : remembered)); |
| 184 set_name(remembered->name()); |
| 185 set_connecting(network ? network->connecting() : false); |
| 186 set_connected(network ? network->connected() : false); |
| 187 set_connectable(true); |
| 188 set_connection_type(remembered->type()); |
| 189 set_remembered(true); |
| 190 set_shared(remembered->profile_type() == chromeos::PROFILE_SHARED); |
| 191 set_needs_new_plan(false); |
| 192 set_policy_managed( |
| 193 network ? chromeos::NetworkUIData::IsManaged(network) : false); |
| 194 } |
| 195 |
| 196 DictionaryValue* NetworkInfoDictionary::BuildDictionary() { |
| 197 std::string status; |
| 198 |
| 199 if (remembered_) { |
| 200 if (shared_) |
| 201 status = l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SHARED_NETWORK); |
| 202 } else { |
| 203 // 802.1X networks can be connected but not have saved credentials, and |
| 204 // hence be "not configured". Give preference to the "connected" and |
| 205 // "connecting" states. http://crosbug.com/14459 |
| 206 int connection_state = IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED; |
| 207 if (connected_) |
| 208 connection_state = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED; |
| 209 else if (connecting_) |
| 210 connection_state = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING; |
| 211 else if (!connectable_) |
| 212 connection_state = IDS_STATUSBAR_NETWORK_DEVICE_NOT_CONFIGURED; |
| 213 status = l10n_util::GetStringUTF8(connection_state); |
| 214 if (connection_type_ == chromeos::TYPE_CELLULAR) { |
| 215 if (needs_new_plan_) { |
| 216 status = l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_NO_PLAN_LABEL); |
| 217 } else if (activation_state_ != chromeos::ACTIVATION_STATE_ACTIVATED) { |
| 218 status.append(" / "); |
| 219 status.append(chromeos::CellularNetwork::ActivationStateToString( |
| 220 activation_state_)); |
| 221 } |
| 222 } |
| 223 } |
| 224 |
| 225 scoped_ptr<DictionaryValue> network_info(new DictionaryValue()); |
| 226 network_info->SetInteger(kNetworkInfoKeyActivationState, |
| 227 static_cast<int>(activation_state_)); |
| 228 network_info->SetBoolean(kNetworkInfoKeyConnectable, connectable_); |
| 229 network_info->SetBoolean(kNetworkInfoKeyConnected, connected_); |
| 230 network_info->SetBoolean(kNetworkInfoKeyConnecting, connecting_); |
| 231 network_info->SetString(kNetworkInfoKeyIconURL, icon_url_); |
| 232 network_info->SetBoolean(kNetworkInfoKeyNeedsNewPlan, needs_new_plan_); |
| 233 network_info->SetString(kNetworkInfoKeyNetworkName, name_); |
| 234 network_info->SetString(kNetworkInfoKeyNetworkStatus, status); |
| 235 network_info->SetInteger(kNetworkInfoKeyNetworkType, |
| 236 static_cast<int>(connection_type_)); |
| 237 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_); |
| 238 network_info->SetString(kNetworkInfoKeyServicePath, service_path_); |
| 239 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_); |
| 240 |
| 241 return network_info.release(); |
| 242 } |
| 243 |
| 244 } // namespace |
| 245 |
| 246 InternetOptionsHandler::InternetOptionsHandler() { |
| 247 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED, |
| 248 content::NotificationService::AllSources()); |
| 249 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED, |
| 250 content::NotificationService::AllSources()); |
| 251 cros_ = chromeos::CrosLibrary::Get()->GetNetworkLibrary(); |
| 252 if (cros_) { |
| 253 cros_->AddNetworkManagerObserver(this); |
| 254 cros_->AddCellularDataPlanObserver(this); |
| 255 MonitorNetworks(); |
| 256 } |
| 257 } |
| 258 |
| 259 InternetOptionsHandler::~InternetOptionsHandler() { |
| 260 if (cros_) { |
| 261 cros_->RemoveNetworkManagerObserver(this); |
| 262 cros_->RemoveCellularDataPlanObserver(this); |
| 263 cros_->RemoveObserverForAllNetworks(this); |
| 264 } |
| 265 } |
| 266 |
| 267 void InternetOptionsHandler::GetLocalizedValues( |
| 268 DictionaryValue* localized_strings) { |
| 269 DCHECK(localized_strings); |
| 270 |
| 271 RegisterTitle(localized_strings, "internetPage", |
| 272 IDS_OPTIONS_INTERNET_TAB_LABEL); |
| 273 |
| 274 localized_strings->SetString("wired_title", |
| 275 l10n_util::GetStringUTF16( |
| 276 IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRED_NETWORK)); |
| 277 localized_strings->SetString("wireless_title", |
| 278 l10n_util::GetStringUTF16( |
| 279 IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIRELESS_NETWORK)); |
| 280 localized_strings->SetString("vpn_title", |
| 281 l10n_util::GetStringUTF16( |
| 282 IDS_OPTIONS_SETTINGS_SECTION_TITLE_VIRTUAL_NETWORK)); |
| 283 localized_strings->SetString("remembered_title", |
| 284 l10n_util::GetStringUTF16( |
| 285 IDS_OPTIONS_SETTINGS_SECTION_TITLE_REMEMBERED_NETWORK)); |
| 286 |
| 287 localized_strings->SetString("connect_button", |
| 288 l10n_util::GetStringUTF16( |
| 289 IDS_OPTIONS_SETTINGS_CONNECT)); |
| 290 localized_strings->SetString("disconnect_button", |
| 291 l10n_util::GetStringUTF16( |
| 292 IDS_OPTIONS_SETTINGS_DISCONNECT)); |
| 293 localized_strings->SetString("options_button", |
| 294 l10n_util::GetStringUTF16( |
| 295 IDS_OPTIONS_SETTINGS_OPTIONS)); |
| 296 localized_strings->SetString("forget_button", |
| 297 l10n_util::GetStringUTF16( |
| 298 IDS_OPTIONS_SETTINGS_FORGET)); |
| 299 localized_strings->SetString("activate_button", |
| 300 l10n_util::GetStringUTF16( |
| 301 IDS_OPTIONS_SETTINGS_ACTIVATE)); |
| 302 localized_strings->SetString("buyplan_button", |
| 303 l10n_util::GetStringUTF16( |
| 304 IDS_OPTIONS_SETTINGS_BUY_PLAN)); |
| 305 |
| 306 localized_strings->SetString("changeProxyButton", |
| 307 l10n_util::GetStringUTF16( |
| 308 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON)); |
| 309 |
| 310 localized_strings->SetString("managedNetwork", |
| 311 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_MANAGED_NETWORK)); |
| 312 |
| 313 localized_strings->SetString("wifiNetworkTabLabel", |
| 314 l10n_util::GetStringUTF16( |
| 315 IDS_OPTIONS_SETTINGS_INTERNET_TAB_WIFI)); |
| 316 localized_strings->SetString("vpnTabLabel", |
| 317 l10n_util::GetStringUTF16( |
| 318 IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN)); |
| 319 localized_strings->SetString("cellularPlanTabLabel", |
| 320 l10n_util::GetStringUTF16( |
| 321 IDS_OPTIONS_SETTINGS_INTERNET_TAB_PLAN)); |
| 322 localized_strings->SetString("cellularConnTabLabel", |
| 323 l10n_util::GetStringUTF16( |
| 324 IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION)); |
| 325 localized_strings->SetString("cellularDeviceTabLabel", |
| 326 l10n_util::GetStringUTF16( |
| 327 IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE)); |
| 328 localized_strings->SetString("networkTabLabel", |
| 329 l10n_util::GetStringUTF16( |
| 330 IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK)); |
| 331 localized_strings->SetString("securityTabLabel", |
| 332 l10n_util::GetStringUTF16( |
| 333 IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY)); |
| 334 |
| 335 localized_strings->SetString("useDHCP", |
| 336 l10n_util::GetStringUTF16( |
| 337 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_DHCP)); |
| 338 localized_strings->SetString("useStaticIP", |
| 339 l10n_util::GetStringUTF16( |
| 340 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_USE_STATIC_IP)); |
| 341 localized_strings->SetString("connectionState", |
| 342 l10n_util::GetStringUTF16( |
| 343 IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE)); |
| 344 localized_strings->SetString("inetAddress", |
| 345 l10n_util::GetStringUTF16( |
| 346 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS)); |
| 347 localized_strings->SetString("inetSubnetAddress", |
| 348 l10n_util::GetStringUTF16( |
| 349 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK)); |
| 350 localized_strings->SetString("inetGateway", |
| 351 l10n_util::GetStringUTF16( |
| 352 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY)); |
| 353 localized_strings->SetString("inetDns", |
| 354 l10n_util::GetStringUTF16( |
| 355 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER)); |
| 356 localized_strings->SetString("hardwareAddress", |
| 357 l10n_util::GetStringUTF16( |
| 358 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS)); |
| 359 |
| 360 // Wifi Tab. |
| 361 localized_strings->SetString("accessLockedMsg", |
| 362 l10n_util::GetStringUTF16( |
| 363 IDS_STATUSBAR_NETWORK_LOCKED)); |
| 364 localized_strings->SetString("inetSsid", |
| 365 l10n_util::GetStringUTF16( |
| 366 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID)); |
| 367 localized_strings->SetString("inetPassProtected", |
| 368 l10n_util::GetStringUTF16( |
| 369 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NET_PROTECTED)); |
| 370 localized_strings->SetString("inetNetworkShared", |
| 371 l10n_util::GetStringUTF16( |
| 372 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_SHARED)); |
| 373 localized_strings->SetString("inetPreferredNetwork", |
| 374 l10n_util::GetStringUTF16( |
| 375 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PREFER_NETWORK)); |
| 376 localized_strings->SetString("inetAutoConnectNetwork", |
| 377 l10n_util::GetStringUTF16( |
| 378 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); |
| 379 localized_strings->SetString("inetLogin", |
| 380 l10n_util::GetStringUTF16( |
| 381 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOGIN)); |
| 382 localized_strings->SetString("inetShowPass", |
| 383 l10n_util::GetStringUTF16( |
| 384 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOWPASSWORD)); |
| 385 localized_strings->SetString("inetPassPrompt", |
| 386 l10n_util::GetStringUTF16( |
| 387 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSWORD)); |
| 388 localized_strings->SetString("inetSsidPrompt", |
| 389 l10n_util::GetStringUTF16( |
| 390 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SSID)); |
| 391 localized_strings->SetString("inetStatus", |
| 392 l10n_util::GetStringUTF16( |
| 393 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_STATUS_TITLE)); |
| 394 localized_strings->SetString("inetConnect", |
| 395 l10n_util::GetStringUTF16( |
| 396 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CONNECT_TITLE)); |
| 397 |
| 398 // VPN Tab. |
| 399 localized_strings->SetString("inetServiceName", |
| 400 l10n_util::GetStringUTF16( |
| 401 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME)); |
| 402 localized_strings->SetString("inetServerHostname", |
| 403 l10n_util::GetStringUTF16( |
| 404 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME)); |
| 405 localized_strings->SetString("inetProviderType", |
| 406 l10n_util::GetStringUTF16( |
| 407 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE)); |
| 408 localized_strings->SetString("inetUsername", |
| 409 l10n_util::GetStringUTF16( |
| 410 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME)); |
| 411 |
| 412 // Cellular Tab. |
| 413 localized_strings->SetString("serviceName", |
| 414 l10n_util::GetStringUTF16( |
| 415 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_SERVICE_NAME)); |
| 416 localized_strings->SetString("networkTechnology", |
| 417 l10n_util::GetStringUTF16( |
| 418 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_NETWORK_TECHNOLOGY)); |
| 419 localized_strings->SetString("operatorName", |
| 420 l10n_util::GetStringUTF16( |
| 421 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR)); |
| 422 localized_strings->SetString("operatorCode", |
| 423 l10n_util::GetStringUTF16( |
| 424 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR_CODE)); |
| 425 localized_strings->SetString("activationState", |
| 426 l10n_util::GetStringUTF16( |
| 427 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACTIVATION_STATE)); |
| 428 localized_strings->SetString("roamingState", |
| 429 l10n_util::GetStringUTF16( |
| 430 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ROAMING_STATE)); |
| 431 localized_strings->SetString("restrictedPool", |
| 432 l10n_util::GetStringUTF16( |
| 433 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_RESTRICTED_POOL)); |
| 434 localized_strings->SetString("errorState", |
| 435 l10n_util::GetStringUTF16( |
| 436 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ERROR_STATE)); |
| 437 localized_strings->SetString("manufacturer", |
| 438 l10n_util::GetStringUTF16( |
| 439 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MANUFACTURER)); |
| 440 localized_strings->SetString("modelId", |
| 441 l10n_util::GetStringUTF16( |
| 442 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MODEL_ID)); |
| 443 localized_strings->SetString("firmwareRevision", |
| 444 l10n_util::GetStringUTF16( |
| 445 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_FIRMWARE_REVISION)); |
| 446 localized_strings->SetString("hardwareRevision", |
| 447 l10n_util::GetStringUTF16( |
| 448 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_HARDWARE_REVISION)); |
| 449 localized_strings->SetString("prlVersion", |
| 450 l10n_util::GetStringUTF16( |
| 451 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_PRL_VERSION)); |
| 452 localized_strings->SetString("cellularApnLabel", |
| 453 l10n_util::GetStringUTF16( |
| 454 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN)); |
| 455 localized_strings->SetString("cellularApnOther", |
| 456 l10n_util::GetStringUTF16( |
| 457 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_OTHER)); |
| 458 localized_strings->SetString("cellularApnUsername", |
| 459 l10n_util::GetStringUTF16( |
| 460 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_USERNAME)); |
| 461 localized_strings->SetString("cellularApnPassword", |
| 462 l10n_util::GetStringUTF16( |
| 463 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_PASSWORD)); |
| 464 localized_strings->SetString("cellularApnUseDefault", |
| 465 l10n_util::GetStringUTF16( |
| 466 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_CLEAR)); |
| 467 localized_strings->SetString("cellularApnSet", |
| 468 l10n_util::GetStringUTF16( |
| 469 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_SET)); |
| 470 localized_strings->SetString("cellularApnCancel", |
| 471 l10n_util::GetStringUTF16( |
| 472 IDS_CANCEL)); |
| 473 |
| 474 localized_strings->SetString("accessSecurityTabLink", |
| 475 l10n_util::GetStringUTF16( |
| 476 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACCESS_SECURITY_TAB)); |
| 477 localized_strings->SetString("lockSimCard", |
| 478 l10n_util::GetStringUTF16( |
| 479 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_LOCK_SIM_CARD)); |
| 480 localized_strings->SetString("changePinButton", |
| 481 l10n_util::GetStringUTF16( |
| 482 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_BUTTON)); |
| 483 |
| 484 localized_strings->SetString("planName", |
| 485 l10n_util::GetStringUTF16( |
| 486 IDS_OPTIONS_SETTINGS_INTERNET_CELL_PLAN_NAME)); |
| 487 localized_strings->SetString("planLoading", |
| 488 l10n_util::GetStringUTF16( |
| 489 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOADING_PLAN)); |
| 490 localized_strings->SetString("noPlansFound", |
| 491 l10n_util::GetStringUTF16( |
| 492 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NO_PLANS_FOUND)); |
| 493 localized_strings->SetString("purchaseMore", |
| 494 l10n_util::GetStringUTF16( |
| 495 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PURCHASE_MORE)); |
| 496 localized_strings->SetString("dataRemaining", |
| 497 l10n_util::GetStringUTF16( |
| 498 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DATA_REMAINING)); |
| 499 localized_strings->SetString("planExpires", |
| 500 l10n_util::GetStringUTF16( |
| 501 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_EXPIRES)); |
| 502 localized_strings->SetString("showPlanNotifications", |
| 503 l10n_util::GetStringUTF16( |
| 504 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOW_MOBILE_NOTIFICATION)); |
| 505 localized_strings->SetString("autoconnectCellular", |
| 506 l10n_util::GetStringUTF16( |
| 507 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT)); |
| 508 localized_strings->SetString("customerSupport", |
| 509 l10n_util::GetStringUTF16( |
| 510 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CUSTOMER_SUPPORT)); |
| 511 |
| 512 localized_strings->SetString("enableWifi", |
| 513 l10n_util::GetStringFUTF16( |
| 514 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, |
| 515 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI))); |
| 516 localized_strings->SetString("disableWifi", |
| 517 l10n_util::GetStringFUTF16( |
| 518 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE, |
| 519 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_WIFI))); |
| 520 localized_strings->SetString("enableCellular", |
| 521 l10n_util::GetStringFUTF16( |
| 522 IDS_STATUSBAR_NETWORK_DEVICE_ENABLE, |
| 523 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR))); |
| 524 localized_strings->SetString("disableCellular", |
| 525 l10n_util::GetStringFUTF16( |
| 526 IDS_STATUSBAR_NETWORK_DEVICE_DISABLE, |
| 527 l10n_util::GetStringUTF16(IDS_STATUSBAR_NETWORK_DEVICE_CELLULAR))); |
| 528 localized_strings->SetString("useSharedProxies", |
| 529 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_USE_SHARED_PROXIES)); |
| 530 localized_strings->SetString("enableDataRoaming", |
| 531 l10n_util::GetStringUTF16(IDS_OPTIONS_SETTINGS_ENABLE_DATA_ROAMING)); |
| 532 localized_strings->SetString("generalNetworkingTitle", |
| 533 l10n_util::GetStringUTF16( |
| 534 IDS_OPTIONS_SETTINGS_INTERNET_CONTROL_TITLE)); |
| 535 localized_strings->SetString("detailsInternetDismiss", |
| 536 l10n_util::GetStringUTF16(IDS_CLOSE)); |
| 537 localized_strings->SetString("ownerOnly", l10n_util::GetStringUTF16( |
| 538 IDS_OPTIONS_ACCOUNTS_OWNER_ONLY)); |
| 539 std::string owner; |
| 540 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner); |
| 541 localized_strings->SetString("ownerUserId", UTF8ToUTF16(owner)); |
| 542 |
| 543 FillNetworkInfo(localized_strings); |
| 544 } |
| 545 |
| 546 void InternetOptionsHandler::Initialize() { |
| 547 cros_->RequestNetworkScan(); |
| 548 } |
| 549 |
| 550 void InternetOptionsHandler::RegisterMessages() { |
| 551 // Setup handlers specific to this panel. |
| 552 DCHECK(web_ui_); |
| 553 web_ui_->RegisterMessageCallback("buttonClickCallback", |
| 554 base::Bind(&InternetOptionsHandler::ButtonClickCallback, |
| 555 base::Unretained(this))); |
| 556 web_ui_->RegisterMessageCallback("refreshCellularPlan", |
| 557 base::Bind(&InternetOptionsHandler::RefreshCellularPlanCallback, |
| 558 base::Unretained(this))); |
| 559 web_ui_->RegisterMessageCallback("setPreferNetwork", |
| 560 base::Bind(&InternetOptionsHandler::SetPreferNetworkCallback, |
| 561 base::Unretained(this))); |
| 562 web_ui_->RegisterMessageCallback("setAutoConnect", |
| 563 base::Bind(&InternetOptionsHandler::SetAutoConnectCallback, |
| 564 base::Unretained(this))); |
| 565 web_ui_->RegisterMessageCallback("setIPConfig", |
| 566 base::Bind(&InternetOptionsHandler::SetIPConfigCallback, |
| 567 base::Unretained(this))); |
| 568 web_ui_->RegisterMessageCallback("enableWifi", |
| 569 base::Bind(&InternetOptionsHandler::EnableWifiCallback, |
| 570 base::Unretained(this))); |
| 571 web_ui_->RegisterMessageCallback("disableWifi", |
| 572 base::Bind(&InternetOptionsHandler::DisableWifiCallback, |
| 573 base::Unretained(this))); |
| 574 web_ui_->RegisterMessageCallback("enableCellular", |
| 575 base::Bind(&InternetOptionsHandler::EnableCellularCallback, |
| 576 base::Unretained(this))); |
| 577 web_ui_->RegisterMessageCallback("disableCellular", |
| 578 base::Bind(&InternetOptionsHandler::DisableCellularCallback, |
| 579 base::Unretained(this))); |
| 580 web_ui_->RegisterMessageCallback("buyDataPlan", |
| 581 base::Bind(&InternetOptionsHandler::BuyDataPlanCallback, |
| 582 base::Unretained(this))); |
| 583 web_ui_->RegisterMessageCallback("showMorePlanInfo", |
| 584 base::Bind(&InternetOptionsHandler::BuyDataPlanCallback, |
| 585 base::Unretained(this))); |
| 586 web_ui_->RegisterMessageCallback("setApn", |
| 587 base::Bind(&InternetOptionsHandler::SetApnCallback, |
| 588 base::Unretained(this))); |
| 589 web_ui_->RegisterMessageCallback("setSimCardLock", |
| 590 base::Bind(&InternetOptionsHandler::SetSimCardLockCallback, |
| 591 base::Unretained(this))); |
| 592 web_ui_->RegisterMessageCallback("changePin", |
| 593 base::Bind(&InternetOptionsHandler::ChangePinCallback, |
| 594 base::Unretained(this))); |
| 595 } |
| 596 |
| 597 void InternetOptionsHandler::EnableWifiCallback(const ListValue* args) { |
| 598 cros_->EnableWifiNetworkDevice(true); |
| 599 } |
| 600 |
| 601 void InternetOptionsHandler::DisableWifiCallback(const ListValue* args) { |
| 602 cros_->EnableWifiNetworkDevice(false); |
| 603 } |
| 604 |
| 605 void InternetOptionsHandler::EnableCellularCallback(const ListValue* args) { |
| 606 const chromeos::NetworkDevice* cellular = cros_->FindCellularDevice(); |
| 607 if (!cellular) { |
| 608 LOG(ERROR) << "Didn't find cellular device, it should have been available."; |
| 609 cros_->EnableCellularNetworkDevice(true); |
| 610 } else if (cellular->sim_lock_state() == chromeos::SIM_UNLOCKED || |
| 611 cellular->sim_lock_state() == chromeos::SIM_UNKNOWN) { |
| 612 cros_->EnableCellularNetworkDevice(true); |
| 613 } else { |
| 614 chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(), |
| 615 chromeos::SimDialogDelegate::SIM_DIALOG_UNLOCK); |
| 616 } |
| 617 } |
| 618 |
| 619 void InternetOptionsHandler::DisableCellularCallback(const ListValue* args) { |
| 620 cros_->EnableCellularNetworkDevice(false); |
| 621 } |
| 622 |
| 623 void InternetOptionsHandler::BuyDataPlanCallback(const ListValue* args) { |
| 624 if (!web_ui_) |
| 625 return; |
| 626 Browser* browser = BrowserList::FindBrowserWithFeature( |
| 627 Profile::FromWebUI(web_ui_), Browser::FEATURE_TABSTRIP); |
| 628 if (browser) |
| 629 browser->OpenMobilePlanTabAndActivate(); |
| 630 } |
| 631 |
| 632 void InternetOptionsHandler::SetApnCallback(const ListValue* args) { |
| 633 std::string service_path; |
| 634 std::string apn; |
| 635 std::string username; |
| 636 std::string password; |
| 637 if (args->GetSize() != 4 || |
| 638 !args->GetString(0, &service_path) || |
| 639 !args->GetString(1, &apn) || |
| 640 !args->GetString(2, &username) || |
| 641 !args->GetString(3, &password)) { |
| 642 NOTREACHED(); |
| 643 return; |
| 644 } |
| 645 |
| 646 chromeos::CellularNetwork* network = |
| 647 cros_->FindCellularNetworkByPath(service_path); |
| 648 if (network) { |
| 649 network->SetApn(chromeos::CellularApn( |
| 650 apn, network->apn().network_id, username, password)); |
| 651 } |
| 652 } |
| 653 |
| 654 void InternetOptionsHandler::SetSimCardLockCallback(const ListValue* args) { |
| 655 bool require_pin_new_value; |
| 656 if (!args->GetBoolean(0, &require_pin_new_value)) { |
| 657 NOTREACHED(); |
| 658 return; |
| 659 } |
| 660 // 1. Bring up SIM unlock dialog, pass new RequirePin setting in URL. |
| 661 // 2. Dialog will ask for current PIN in any case. |
| 662 // 3. If card is locked it will first call PIN unlock operation |
| 663 // 4. Then it will call Set RequirePin, passing the same PIN. |
| 664 // 5. We'll get notified by REQUIRE_PIN_SETTING_CHANGE_ENDED notification. |
| 665 chromeos::SimDialogDelegate::SimDialogMode mode; |
| 666 if (require_pin_new_value) |
| 667 mode = chromeos::SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON; |
| 668 else |
| 669 mode = chromeos::SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF; |
| 670 chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(), mode); |
| 671 } |
| 672 |
| 673 void InternetOptionsHandler::ChangePinCallback(const ListValue* args) { |
| 674 chromeos::SimDialogDelegate::ShowDialog(GetNativeWindow(), |
| 675 chromeos::SimDialogDelegate::SIM_DIALOG_CHANGE_PIN); |
| 676 } |
| 677 |
| 678 void InternetOptionsHandler::RefreshNetworkData() { |
| 679 DictionaryValue dictionary; |
| 680 FillNetworkInfo(&dictionary); |
| 681 web_ui_->CallJavascriptFunction( |
| 682 "options.InternetOptions.refreshNetworkData", dictionary); |
| 683 } |
| 684 |
| 685 void InternetOptionsHandler::OnNetworkManagerChanged( |
| 686 chromeos::NetworkLibrary* cros) { |
| 687 if (!web_ui_) |
| 688 return; |
| 689 MonitorNetworks(); |
| 690 RefreshNetworkData(); |
| 691 } |
| 692 |
| 693 void InternetOptionsHandler::OnNetworkChanged( |
| 694 chromeos::NetworkLibrary* cros, |
| 695 const chromeos::Network* network) { |
| 696 if (web_ui_) |
| 697 RefreshNetworkData(); |
| 698 } |
| 699 |
| 700 // Monitor wireless networks for changes. It is only necessary |
| 701 // to set up individual observers for the cellular networks |
| 702 // (if any) and for the connected Wi-Fi network (if any). The |
| 703 // only change we are interested in for Wi-Fi networks is signal |
| 704 // strength. For non-connected Wi-Fi networks, all information is |
| 705 // reported via scan results, which trigger network manager |
| 706 // updates. Only the connected Wi-Fi network has changes reported |
| 707 // via service property updates. |
| 708 void InternetOptionsHandler::MonitorNetworks() { |
| 709 cros_->RemoveObserverForAllNetworks(this); |
| 710 const chromeos::WifiNetwork* wifi_network = cros_->wifi_network(); |
| 711 if (wifi_network) |
| 712 cros_->AddNetworkObserver(wifi_network->service_path(), this); |
| 713 // Always monitor the cellular networks, if any, so that changes |
| 714 // in network technology, roaming status, and signal strength |
| 715 // will be shown. |
| 716 const chromeos::CellularNetworkVector& cell_networks = |
| 717 cros_->cellular_networks(); |
| 718 for (size_t i = 0; i < cell_networks.size(); ++i) { |
| 719 chromeos::CellularNetwork* cell_network = cell_networks[i]; |
| 720 cros_->AddNetworkObserver(cell_network->service_path(), this); |
| 721 } |
| 722 const chromeos::VirtualNetwork* virtual_network = cros_->virtual_network(); |
| 723 if (virtual_network) |
| 724 cros_->AddNetworkObserver(virtual_network->service_path(), this); |
| 725 } |
| 726 |
| 727 void InternetOptionsHandler::OnCellularDataPlanChanged( |
| 728 chromeos::NetworkLibrary* cros) { |
| 729 if (!web_ui_) |
| 730 return; |
| 731 const chromeos::CellularNetwork* cellular = cros_->cellular_network(); |
| 732 if (!cellular) |
| 733 return; |
| 734 const chromeos::CellularDataPlanVector* plans = |
| 735 cros_->GetDataPlans(cellular->service_path()); |
| 736 DictionaryValue connection_plans; |
| 737 ListValue* plan_list = new ListValue(); |
| 738 if (plans) { |
| 739 for (chromeos::CellularDataPlanVector::const_iterator iter = plans->begin(); |
| 740 iter != plans->end(); ++iter) { |
| 741 plan_list->Append(CellularDataPlanToDictionary(*iter)); |
| 742 } |
| 743 } |
| 744 connection_plans.SetString("servicePath", cellular->service_path()); |
| 745 connection_plans.SetBoolean("needsPlan", cellular->needs_new_plan()); |
| 746 connection_plans.SetBoolean("activated", |
| 747 cellular->activation_state() == chromeos::ACTIVATION_STATE_ACTIVATED); |
| 748 connection_plans.Set("plans", plan_list); |
| 749 SetActivationButtonVisibility(cellular, &connection_plans); |
| 750 web_ui_->CallJavascriptFunction( |
| 751 "options.InternetOptions.updateCellularPlans", connection_plans); |
| 752 } |
| 753 |
| 754 |
| 755 void InternetOptionsHandler::Observe( |
| 756 int type, |
| 757 const content::NotificationSource& source, |
| 758 const content::NotificationDetails& details) { |
| 759 OptionsPage2UIHandler::Observe(type, source, details); |
| 760 if (type == chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED) { |
| 761 base::FundamentalValue require_pin(*content::Details<bool>(details).ptr()); |
| 762 web_ui_->CallJavascriptFunction( |
| 763 "options.InternetOptions.updateSecurityTab", require_pin); |
| 764 } else if (type == chrome::NOTIFICATION_ENTER_PIN_ENDED) { |
| 765 // We make an assumption (which is valid for now) that the SIM |
| 766 // unlock dialog is put up only when the user is trying to enable |
| 767 // mobile data. |
| 768 bool cancelled = *content::Details<bool>(details).ptr(); |
| 769 if (cancelled) { |
| 770 base::DictionaryValue dictionary; |
| 771 FillNetworkInfo(&dictionary); |
| 772 web_ui_->CallJavascriptFunction( |
| 773 "options.InternetOptions.setupAttributes", dictionary); |
| 774 } |
| 775 // The case in which the correct PIN was entered and the SIM is |
| 776 // now unlocked is handled in NetworkMenuButton. |
| 777 } |
| 778 } |
| 779 |
| 780 DictionaryValue* InternetOptionsHandler::CellularDataPlanToDictionary( |
| 781 const chromeos::CellularDataPlan* plan) { |
| 782 DictionaryValue* plan_dict = new DictionaryValue(); |
| 783 plan_dict->SetInteger("planType", plan->plan_type); |
| 784 plan_dict->SetString("name", plan->plan_name); |
| 785 plan_dict->SetString("planSummary", plan->GetPlanDesciption()); |
| 786 plan_dict->SetString("dataRemaining", plan->GetDataRemainingDesciption()); |
| 787 plan_dict->SetString("planExpires", plan->GetPlanExpiration()); |
| 788 plan_dict->SetString("warning", plan->GetRemainingWarning()); |
| 789 return plan_dict; |
| 790 } |
| 791 |
| 792 void InternetOptionsHandler::SetPreferNetworkCallback(const ListValue* args) { |
| 793 std::string service_path; |
| 794 std::string prefer_network_str; |
| 795 |
| 796 if (args->GetSize() < 2 || |
| 797 !args->GetString(0, &service_path) || |
| 798 !args->GetString(1, &prefer_network_str)) { |
| 799 NOTREACHED(); |
| 800 return; |
| 801 } |
| 802 |
| 803 chromeos::Network* network = cros_->FindNetworkByPath(service_path); |
| 804 if (!network) |
| 805 return; |
| 806 |
| 807 bool prefer_network = prefer_network_str == "true"; |
| 808 if (prefer_network != network->preferred()) |
| 809 network->SetPreferred(prefer_network); |
| 810 } |
| 811 |
| 812 void InternetOptionsHandler::SetAutoConnectCallback(const ListValue* args) { |
| 813 std::string service_path; |
| 814 std::string auto_connect_str; |
| 815 |
| 816 if (args->GetSize() < 2 || |
| 817 !args->GetString(0, &service_path) || |
| 818 !args->GetString(1, &auto_connect_str)) { |
| 819 NOTREACHED(); |
| 820 return; |
| 821 } |
| 822 |
| 823 chromeos::Network* network = cros_->FindNetworkByPath(service_path); |
| 824 if (!network) |
| 825 return; |
| 826 |
| 827 bool auto_connect = auto_connect_str == "true"; |
| 828 if (auto_connect != network->auto_connect()) |
| 829 network->SetAutoConnect(auto_connect); |
| 830 } |
| 831 |
| 832 void InternetOptionsHandler::SetIPConfigCallback(const ListValue* args) { |
| 833 std::string service_path; |
| 834 std::string dhcp_str; |
| 835 std::string address; |
| 836 std::string netmask; |
| 837 std::string gateway; |
| 838 std::string name_servers; |
| 839 |
| 840 if (args->GetSize() < 6 || |
| 841 !args->GetString(0, &service_path) || |
| 842 !args->GetString(1, &dhcp_str) || |
| 843 !args->GetString(2, &address) || |
| 844 !args->GetString(3, &netmask) || |
| 845 !args->GetString(4, &gateway) || |
| 846 !args->GetString(5, &name_servers)) { |
| 847 NOTREACHED(); |
| 848 return; |
| 849 } |
| 850 |
| 851 chromeos::Network* network = cros_->FindNetworkByPath(service_path); |
| 852 if (!network) |
| 853 return; |
| 854 |
| 855 cros_->SetIPConfig(chromeos::NetworkIPConfig(network->device_path(), |
| 856 dhcp_str == "true" ? chromeos::IPCONFIG_TYPE_DHCP : |
| 857 chromeos::IPCONFIG_TYPE_IPV4, |
| 858 address, netmask, gateway, name_servers)); |
| 859 } |
| 860 |
| 861 void InternetOptionsHandler::PopulateDictionaryDetails( |
| 862 const chromeos::Network* network) { |
| 863 DCHECK(network); |
| 864 |
| 865 if (web_ui_) { |
| 866 Profile::FromWebUI(web_ui_)->GetProxyConfigTracker()->UISetCurrentNetwork( |
| 867 network->service_path()); |
| 868 } |
| 869 |
| 870 DictionaryValue dictionary; |
| 871 std::string hardware_address; |
| 872 chromeos::NetworkIPConfigVector ipconfigs = cros_->GetIPConfigs( |
| 873 network->device_path(), &hardware_address, |
| 874 chromeos::NetworkLibrary::FORMAT_COLON_SEPARATED_HEX); |
| 875 if (!hardware_address.empty()) |
| 876 dictionary.SetString("hardwareAddress", hardware_address); |
| 877 |
| 878 scoped_ptr<DictionaryValue> ipconfig_dhcp; |
| 879 scoped_ptr<DictionaryValue> ipconfig_static; |
| 880 for (chromeos::NetworkIPConfigVector::const_iterator it = ipconfigs.begin(); |
| 881 it != ipconfigs.end(); ++it) { |
| 882 const chromeos::NetworkIPConfig& ipconfig = *it; |
| 883 scoped_ptr<DictionaryValue> ipconfig_dict(new DictionaryValue()); |
| 884 ipconfig_dict->SetString("address", ipconfig.address); |
| 885 ipconfig_dict->SetString("subnetAddress", ipconfig.netmask); |
| 886 ipconfig_dict->SetString("gateway", ipconfig.gateway); |
| 887 ipconfig_dict->SetString("dns", ipconfig.name_servers); |
| 888 if (ipconfig.type == chromeos::IPCONFIG_TYPE_DHCP) |
| 889 ipconfig_dhcp.reset(ipconfig_dict.release()); |
| 890 else if (ipconfig.type == chromeos::IPCONFIG_TYPE_IPV4) |
| 891 ipconfig_static.reset(ipconfig_dict.release()); |
| 892 } |
| 893 |
| 894 chromeos::NetworkPropertyUIData ipconfig_dhcp_ui_data(network, NULL); |
| 895 SetValueDictionary(&dictionary, "ipconfigDHCP", ipconfig_dhcp.release(), |
| 896 ipconfig_dhcp_ui_data); |
| 897 chromeos::NetworkPropertyUIData ipconfig_static_ui_data(network, NULL); |
| 898 SetValueDictionary(&dictionary, "ipconfigStatic", ipconfig_static.release(), |
| 899 ipconfig_static_ui_data); |
| 900 |
| 901 chromeos::ConnectionType type = network->type(); |
| 902 dictionary.SetInteger("type", type); |
| 903 dictionary.SetString("servicePath", network->service_path()); |
| 904 dictionary.SetBoolean("connecting", network->connecting()); |
| 905 dictionary.SetBoolean("connected", network->connected()); |
| 906 dictionary.SetString("connectionState", network->GetStateString()); |
| 907 |
| 908 // Only show proxy for remembered networks. |
| 909 chromeos::NetworkProfileType network_profile = network->profile_type(); |
| 910 dictionary.SetBoolean("showProxy", network_profile != chromeos::PROFILE_NONE); |
| 911 |
| 912 // Hide the dhcp/static radio if not ethernet or wifi (or if not enabled) |
| 913 bool staticIPConfig = CommandLine::ForCurrentProcess()->HasSwitch( |
| 914 switches::kEnableStaticIPConfig); |
| 915 dictionary.SetBoolean("showStaticIPConfig", staticIPConfig && |
| 916 (type == chromeos::TYPE_WIFI || type == chromeos::TYPE_ETHERNET)); |
| 917 |
| 918 chromeos::NetworkPropertyUIData preferred_ui_data( |
| 919 network, chromeos::NetworkUIData::kPropertyPreferred); |
| 920 if (network_profile == chromeos::PROFILE_USER) { |
| 921 dictionary.SetBoolean("showPreferred", true); |
| 922 SetValueDictionary(&dictionary, "preferred", |
| 923 Value::CreateBooleanValue(network->preferred()), |
| 924 preferred_ui_data); |
| 925 } else { |
| 926 dictionary.SetBoolean("showPreferred", false); |
| 927 SetValueDictionary(&dictionary, "preferred", |
| 928 Value::CreateBooleanValue(network->preferred()), |
| 929 preferred_ui_data); |
| 930 } |
| 931 chromeos::NetworkPropertyUIData auto_connect_ui_data( |
| 932 network, chromeos::NetworkUIData::kPropertyAutoConnect); |
| 933 SetValueDictionary(&dictionary, "autoConnect", |
| 934 Value::CreateBooleanValue(network->auto_connect()), |
| 935 auto_connect_ui_data); |
| 936 |
| 937 if (type == chromeos::TYPE_WIFI) { |
| 938 dictionary.SetBoolean("deviceConnected", cros_->wifi_connected()); |
| 939 const chromeos::WifiNetwork* wifi = |
| 940 cros_->FindWifiNetworkByPath(network->service_path()); |
| 941 if (!wifi) { |
| 942 LOG(WARNING) << "Cannot find network " << network->service_path(); |
| 943 } else { |
| 944 PopulateWifiDetails(wifi, &dictionary); |
| 945 } |
| 946 } else if (type == chromeos::TYPE_CELLULAR) { |
| 947 dictionary.SetBoolean("deviceConnected", cros_->cellular_connected()); |
| 948 const chromeos::CellularNetwork* cellular = |
| 949 cros_->FindCellularNetworkByPath(network->service_path()); |
| 950 if (!cellular) { |
| 951 LOG(WARNING) << "Cannot find network " << network->service_path(); |
| 952 } else { |
| 953 PopulateCellularDetails(cellular, &dictionary); |
| 954 } |
| 955 } else if (type == chromeos::TYPE_VPN) { |
| 956 dictionary.SetBoolean("deviceConnected", |
| 957 cros_->virtual_network_connected()); |
| 958 const chromeos::VirtualNetwork* vpn = |
| 959 cros_->FindVirtualNetworkByPath(network->service_path()); |
| 960 if (!vpn) { |
| 961 LOG(WARNING) << "Cannot find network " << network->service_path(); |
| 962 } else { |
| 963 PopulateVPNDetails(vpn, &dictionary); |
| 964 } |
| 965 } else if (type == chromeos::TYPE_ETHERNET) { |
| 966 dictionary.SetBoolean("deviceConnected", cros_->ethernet_connected()); |
| 967 } |
| 968 |
| 969 web_ui_->CallJavascriptFunction( |
| 970 "options.InternetOptions.showDetailedInfo", dictionary); |
| 971 } |
| 972 |
| 973 void InternetOptionsHandler::PopulateWifiDetails( |
| 974 const chromeos::WifiNetwork* wifi, |
| 975 DictionaryValue* dictionary) { |
| 976 dictionary->SetString("ssid", wifi->name()); |
| 977 bool remembered = (wifi->profile_type() != chromeos::PROFILE_NONE); |
| 978 dictionary->SetBoolean("remembered", remembered); |
| 979 dictionary->SetBoolean("encrypted", wifi->encrypted()); |
| 980 bool shared = wifi->profile_type() == chromeos::PROFILE_SHARED; |
| 981 dictionary->SetBoolean("shared", shared); |
| 982 } |
| 983 |
| 984 DictionaryValue* InternetOptionsHandler::CreateDictionaryFromCellularApn( |
| 985 const chromeos::CellularApn& apn) { |
| 986 DictionaryValue* dictionary = new DictionaryValue(); |
| 987 dictionary->SetString("apn", apn.apn); |
| 988 dictionary->SetString("networkId", apn.network_id); |
| 989 dictionary->SetString("username", apn.username); |
| 990 dictionary->SetString("password", apn.password); |
| 991 dictionary->SetString("name", apn.name); |
| 992 dictionary->SetString("localizedName", apn.localized_name); |
| 993 dictionary->SetString("language", apn.language); |
| 994 return dictionary; |
| 995 } |
| 996 |
| 997 void InternetOptionsHandler::PopulateCellularDetails( |
| 998 const chromeos::CellularNetwork* cellular, |
| 999 DictionaryValue* dictionary) { |
| 1000 // Cellular network / connection settings. |
| 1001 dictionary->SetString("serviceName", cellular->name()); |
| 1002 dictionary->SetString("networkTechnology", |
| 1003 cellular->GetNetworkTechnologyString()); |
| 1004 dictionary->SetString("operatorName", cellular->operator_name()); |
| 1005 dictionary->SetString("operatorCode", cellular->operator_code()); |
| 1006 dictionary->SetString("activationState", |
| 1007 cellular->GetActivationStateString()); |
| 1008 dictionary->SetString("roamingState", |
| 1009 cellular->GetRoamingStateString()); |
| 1010 dictionary->SetString("restrictedPool", |
| 1011 cellular->restricted_pool() ? |
| 1012 l10n_util::GetStringUTF8( |
| 1013 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) : |
| 1014 l10n_util::GetStringUTF8( |
| 1015 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL)); |
| 1016 dictionary->SetString("errorState", cellular->GetErrorString()); |
| 1017 dictionary->SetString("supportUrl", cellular->payment_url()); |
| 1018 dictionary->SetBoolean("needsPlan", cellular->needs_new_plan()); |
| 1019 |
| 1020 dictionary->Set("apn", CreateDictionaryFromCellularApn(cellular->apn())); |
| 1021 dictionary->Set("lastGoodApn", |
| 1022 CreateDictionaryFromCellularApn(cellular->last_good_apn())); |
| 1023 |
| 1024 // Device settings. |
| 1025 const chromeos::NetworkDevice* device = |
| 1026 cros_->FindNetworkDeviceByPath(cellular->device_path()); |
| 1027 if (device) { |
| 1028 chromeos::NetworkPropertyUIData cellular_propety_ui_data(cellular, NULL); |
| 1029 dictionary->SetString("manufacturer", device->manufacturer()); |
| 1030 dictionary->SetString("modelId", device->model_id()); |
| 1031 dictionary->SetString("firmwareRevision", device->firmware_revision()); |
| 1032 dictionary->SetString("hardwareRevision", device->hardware_revision()); |
| 1033 dictionary->SetString("prlVersion", |
| 1034 base::StringPrintf("%u", device->prl_version())); |
| 1035 dictionary->SetString("meid", device->meid()); |
| 1036 dictionary->SetString("imei", device->imei()); |
| 1037 dictionary->SetString("mdn", device->mdn()); |
| 1038 dictionary->SetString("imsi", device->imsi()); |
| 1039 dictionary->SetString("esn", device->esn()); |
| 1040 dictionary->SetString("min", device->min()); |
| 1041 dictionary->SetBoolean("gsm", |
| 1042 device->technology_family() == chromeos::TECHNOLOGY_FAMILY_GSM); |
| 1043 SetValueDictionary( |
| 1044 dictionary, "simCardLockEnabled", |
| 1045 Value::CreateBooleanValue( |
| 1046 device->sim_pin_required() == chromeos::SIM_PIN_REQUIRED), |
| 1047 cellular_propety_ui_data); |
| 1048 |
| 1049 chromeos::MobileConfig* config = chromeos::MobileConfig::GetInstance(); |
| 1050 if (config->IsReady()) { |
| 1051 std::string carrier_id = cros_->GetCellularHomeCarrierId(); |
| 1052 const chromeos::MobileConfig::Carrier* carrier = |
| 1053 config->GetCarrier(carrier_id); |
| 1054 if (carrier && !carrier->top_up_url().empty()) |
| 1055 dictionary->SetString("carrierUrl", carrier->top_up_url()); |
| 1056 } |
| 1057 |
| 1058 const chromeos::CellularApnList& apn_list = device->provider_apn_list(); |
| 1059 ListValue* apn_list_value = new ListValue(); |
| 1060 for (chromeos::CellularApnList::const_iterator it = apn_list.begin(); |
| 1061 it != apn_list.end(); ++it) { |
| 1062 apn_list_value->Append(CreateDictionaryFromCellularApn(*it)); |
| 1063 } |
| 1064 SetValueDictionary(dictionary, "providerApnList", apn_list_value, |
| 1065 cellular_propety_ui_data); |
| 1066 } |
| 1067 |
| 1068 SetActivationButtonVisibility(cellular, dictionary); |
| 1069 } |
| 1070 |
| 1071 void InternetOptionsHandler::PopulateVPNDetails( |
| 1072 const chromeos::VirtualNetwork* vpn, |
| 1073 DictionaryValue* dictionary) { |
| 1074 dictionary->SetString("service_name", vpn->name()); |
| 1075 bool remembered = (vpn->profile_type() != chromeos::PROFILE_NONE); |
| 1076 dictionary->SetBoolean("remembered", remembered); |
| 1077 dictionary->SetString("server_hostname", vpn->server_hostname()); |
| 1078 dictionary->SetString("provider_type", vpn->GetProviderTypeString()); |
| 1079 dictionary->SetString("username", vpn->username()); |
| 1080 } |
| 1081 |
| 1082 void InternetOptionsHandler::SetActivationButtonVisibility( |
| 1083 const chromeos::CellularNetwork* cellular, |
| 1084 DictionaryValue* dictionary) { |
| 1085 if (cellular->needs_new_plan()) { |
| 1086 dictionary->SetBoolean("showBuyButton", true); |
| 1087 } else if (cellular->activation_state() != |
| 1088 chromeos::ACTIVATION_STATE_ACTIVATING && |
| 1089 cellular->activation_state() != |
| 1090 chromeos::ACTIVATION_STATE_ACTIVATED) { |
| 1091 dictionary->SetBoolean("showActivateButton", true); |
| 1092 } |
| 1093 } |
| 1094 |
| 1095 void InternetOptionsHandler::CreateModalPopup(views::WidgetDelegate* view) { |
| 1096 views::Widget* window = browser::CreateViewsWindow(GetNativeWindow(), |
| 1097 view, |
| 1098 STYLE_GENERIC); |
| 1099 window->SetAlwaysOnTop(true); |
| 1100 window->Show(); |
| 1101 } |
| 1102 |
| 1103 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { |
| 1104 // TODO(beng): This is an improper direct dependency on Browser. Route this |
| 1105 // through some sort of delegate. |
| 1106 Browser* browser = |
| 1107 BrowserList::FindBrowserWithProfile(Profile::FromWebUI(web_ui_)); |
| 1108 return browser->window()->GetNativeHandle(); |
| 1109 } |
| 1110 |
| 1111 void InternetOptionsHandler::ButtonClickCallback(const ListValue* args) { |
| 1112 std::string str_type; |
| 1113 std::string service_path; |
| 1114 std::string command; |
| 1115 if (args->GetSize() != 3 || |
| 1116 !args->GetString(0, &str_type) || |
| 1117 !args->GetString(1, &service_path) || |
| 1118 !args->GetString(2, &command)) { |
| 1119 NOTREACHED(); |
| 1120 return; |
| 1121 } |
| 1122 |
| 1123 int type = atoi(str_type.c_str()); |
| 1124 if (type == chromeos::TYPE_ETHERNET) { |
| 1125 const chromeos::EthernetNetwork* ether = cros_->ethernet_network(); |
| 1126 if (ether) |
| 1127 PopulateDictionaryDetails(ether); |
| 1128 } else if (type == chromeos::TYPE_WIFI) { |
| 1129 HandleWifiButtonClick(service_path, command); |
| 1130 } else if (type == chromeos::TYPE_CELLULAR) { |
| 1131 HandleCellularButtonClick(service_path, command); |
| 1132 } else if (type == chromeos::TYPE_VPN) { |
| 1133 HandleVPNButtonClick(service_path, command); |
| 1134 } else { |
| 1135 NOTREACHED(); |
| 1136 } |
| 1137 } |
| 1138 |
| 1139 void InternetOptionsHandler::HandleWifiButtonClick( |
| 1140 const std::string& service_path, |
| 1141 const std::string& command) { |
| 1142 chromeos::WifiNetwork* wifi = NULL; |
| 1143 if (command == "forget") { |
| 1144 cros_->ForgetNetwork(service_path); |
| 1145 } else if (service_path == kOtherNetworksFakePath) { |
| 1146 // Other wifi networks. |
| 1147 CreateModalPopup(new chromeos::NetworkConfigView(chromeos::TYPE_WIFI)); |
| 1148 } else if ((wifi = cros_->FindWifiNetworkByPath(service_path))) { |
| 1149 if (command == "connect") { |
| 1150 // Connect to wifi here. Open password page if appropriate. |
| 1151 if (wifi->IsPassphraseRequired()) { |
| 1152 CreateModalPopup(new chromeos::NetworkConfigView(wifi)); |
| 1153 } else { |
| 1154 cros_->ConnectToWifiNetwork(wifi); |
| 1155 } |
| 1156 } else if (command == "disconnect") { |
| 1157 cros_->DisconnectFromNetwork(wifi); |
| 1158 } else if (command == "options") { |
| 1159 PopulateDictionaryDetails(wifi); |
| 1160 } |
| 1161 } |
| 1162 } |
| 1163 |
| 1164 void InternetOptionsHandler::HandleCellularButtonClick( |
| 1165 const std::string& service_path, |
| 1166 const std::string& command) { |
| 1167 chromeos::CellularNetwork* cellular = NULL; |
| 1168 if (service_path == kOtherNetworksFakePath) { |
| 1169 chromeos::ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow()); |
| 1170 } else if ((cellular = cros_->FindCellularNetworkByPath(service_path))) { |
| 1171 if (command == "connect") { |
| 1172 cros_->ConnectToCellularNetwork(cellular); |
| 1173 } else if (command == "disconnect") { |
| 1174 cros_->DisconnectFromNetwork(cellular); |
| 1175 } else if (command == "activate") { |
| 1176 Browser* browser = BrowserList::GetLastActive(); |
| 1177 if (browser) |
| 1178 browser->OpenMobilePlanTabAndActivate(); |
| 1179 } else if (command == "options") { |
| 1180 PopulateDictionaryDetails(cellular); |
| 1181 } |
| 1182 } |
| 1183 } |
| 1184 |
| 1185 void InternetOptionsHandler::HandleVPNButtonClick( |
| 1186 const std::string& service_path, |
| 1187 const std::string& command) { |
| 1188 chromeos::VirtualNetwork* network = NULL; |
| 1189 if (command == "forget") { |
| 1190 cros_->ForgetNetwork(service_path); |
| 1191 } else if (service_path == kOtherNetworksFakePath) { |
| 1192 // TODO(altimofeev): verify if service_path in condition is correct. |
| 1193 // Other VPN networks. |
| 1194 CreateModalPopup(new chromeos::NetworkConfigView(chromeos::TYPE_VPN)); |
| 1195 } else if ((network = cros_->FindVirtualNetworkByPath(service_path))) { |
| 1196 if (command == "connect") { |
| 1197 // Connect to VPN here. Open password page if appropriate. |
| 1198 if (network->NeedMoreInfoToConnect()) { |
| 1199 CreateModalPopup(new chromeos::NetworkConfigView(network)); |
| 1200 } else { |
| 1201 cros_->ConnectToVirtualNetwork(network); |
| 1202 } |
| 1203 } else if (command == "disconnect") { |
| 1204 cros_->DisconnectFromNetwork(network); |
| 1205 } else if (command == "options") { |
| 1206 PopulateDictionaryDetails(network); |
| 1207 } |
| 1208 } |
| 1209 } |
| 1210 |
| 1211 void InternetOptionsHandler::RefreshCellularPlanCallback( |
| 1212 const ListValue* args) { |
| 1213 std::string service_path; |
| 1214 if (args->GetSize() != 1 || |
| 1215 !args->GetString(0, &service_path)) { |
| 1216 NOTREACHED(); |
| 1217 return; |
| 1218 } |
| 1219 const chromeos::CellularNetwork* cellular = |
| 1220 cros_->FindCellularNetworkByPath(service_path); |
| 1221 if (cellular) |
| 1222 cellular->RefreshDataPlansIfNeeded(); |
| 1223 } |
| 1224 |
| 1225 ListValue* InternetOptionsHandler::GetWiredList() { |
| 1226 ListValue* list = new ListValue(); |
| 1227 |
| 1228 // If ethernet is not enabled, then don't add anything. |
| 1229 if (cros_->ethernet_enabled()) { |
| 1230 const chromeos::EthernetNetwork* ethernet_network = |
| 1231 cros_->ethernet_network(); |
| 1232 if (ethernet_network) { |
| 1233 NetworkInfoDictionary network_dict(ethernet_network); |
| 1234 network_dict.set_name( |
| 1235 l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET)), |
| 1236 list->Append(network_dict.BuildDictionary()); |
| 1237 } |
| 1238 } |
| 1239 return list; |
| 1240 } |
| 1241 |
| 1242 ListValue* InternetOptionsHandler::GetWirelessList() { |
| 1243 ListValue* list = new ListValue(); |
| 1244 |
| 1245 const chromeos::WifiNetworkVector& wifi_networks = cros_->wifi_networks(); |
| 1246 for (chromeos::WifiNetworkVector::const_iterator it = |
| 1247 wifi_networks.begin(); it != wifi_networks.end(); ++it) { |
| 1248 NetworkInfoDictionary network_dict(*it); |
| 1249 network_dict.set_connectable(cros_->CanConnectToNetwork(*it)); |
| 1250 list->Append(network_dict.BuildDictionary()); |
| 1251 } |
| 1252 |
| 1253 // Add "Other WiFi network..." if wifi is enabled. |
| 1254 if (cros_->wifi_enabled()) { |
| 1255 NetworkInfoDictionary network_dict; |
| 1256 network_dict.set_service_path(kOtherNetworksFakePath); |
| 1257 network_dict.set_icon( |
| 1258 chromeos::NetworkMenuIcon::GetConnectedBitmap( |
| 1259 chromeos::NetworkMenuIcon::ARCS)); |
| 1260 network_dict.set_name( |
| 1261 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_OTHER_WIFI_NETWORKS)); |
| 1262 network_dict.set_connectable(true); |
| 1263 network_dict.set_connection_type(chromeos::TYPE_WIFI); |
| 1264 list->Append(network_dict.BuildDictionary()); |
| 1265 } |
| 1266 |
| 1267 const chromeos::CellularNetworkVector cellular_networks = |
| 1268 cros_->cellular_networks(); |
| 1269 for (chromeos::CellularNetworkVector::const_iterator it = |
| 1270 cellular_networks.begin(); it != cellular_networks.end(); ++it) { |
| 1271 NetworkInfoDictionary network_dict(*it); |
| 1272 network_dict.set_connectable(cros_->CanConnectToNetwork(*it)); |
| 1273 network_dict.set_activation_state((*it)->activation_state()); |
| 1274 network_dict.set_needs_new_plan( |
| 1275 (*it)->SupportsDataPlan() && (*it)->restricted_pool()); |
| 1276 list->Append(network_dict.BuildDictionary()); |
| 1277 } |
| 1278 |
| 1279 const chromeos::NetworkDevice* cellular_device = cros_->FindCellularDevice(); |
| 1280 if (cellular_device && cellular_device->support_network_scan() && |
| 1281 cros_->cellular_enabled()) { |
| 1282 NetworkInfoDictionary network_dict; |
| 1283 network_dict.set_service_path(kOtherNetworksFakePath); |
| 1284 network_dict.set_icon( |
| 1285 chromeos::NetworkMenuIcon::GetDisconnectedBitmap( |
| 1286 chromeos::NetworkMenuIcon::BARS)); |
| 1287 network_dict.set_name( |
| 1288 l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_OTHER_CELLULAR_NETWORKS)); |
| 1289 network_dict.set_connectable(true); |
| 1290 network_dict.set_connection_type(chromeos::TYPE_CELLULAR); |
| 1291 network_dict.set_activation_state(chromeos::ACTIVATION_STATE_ACTIVATED); |
| 1292 list->Append(network_dict.BuildDictionary()); |
| 1293 } |
| 1294 |
| 1295 return list; |
| 1296 } |
| 1297 |
| 1298 ListValue* InternetOptionsHandler::GetVPNList() { |
| 1299 ListValue* list = new ListValue(); |
| 1300 |
| 1301 const chromeos::VirtualNetworkVector& virtual_networks = |
| 1302 cros_->virtual_networks(); |
| 1303 for (chromeos::VirtualNetworkVector::const_iterator it = |
| 1304 virtual_networks.begin(); it != virtual_networks.end(); ++it) { |
| 1305 NetworkInfoDictionary network_dict(*it); |
| 1306 network_dict.set_connectable(cros_->CanConnectToNetwork(*it)); |
| 1307 list->Append(network_dict.BuildDictionary()); |
| 1308 } |
| 1309 |
| 1310 return list; |
| 1311 } |
| 1312 |
| 1313 ListValue* InternetOptionsHandler::GetRememberedList() { |
| 1314 ListValue* list = new ListValue(); |
| 1315 |
| 1316 for (chromeos::WifiNetworkVector::const_iterator rit = |
| 1317 cros_->remembered_wifi_networks().begin(); |
| 1318 rit != cros_->remembered_wifi_networks().end(); ++rit) { |
| 1319 chromeos::WifiNetwork* remembered = *rit; |
| 1320 chromeos::WifiNetwork* wifi = static_cast<chromeos::WifiNetwork*>( |
| 1321 cros_->FindNetworkByUniqueId(remembered->unique_id())); |
| 1322 |
| 1323 NetworkInfoDictionary network_dict(wifi, remembered); |
| 1324 list->Append(network_dict.BuildDictionary()); |
| 1325 } |
| 1326 |
| 1327 for (chromeos::VirtualNetworkVector::const_iterator rit = |
| 1328 cros_->remembered_virtual_networks().begin(); |
| 1329 rit != cros_->remembered_virtual_networks().end(); ++rit) { |
| 1330 chromeos::VirtualNetwork* remembered = *rit; |
| 1331 chromeos::VirtualNetwork* vpn = static_cast<chromeos::VirtualNetwork*>( |
| 1332 cros_->FindNetworkByUniqueId(remembered->unique_id())); |
| 1333 |
| 1334 NetworkInfoDictionary network_dict(vpn, remembered); |
| 1335 list->Append(network_dict.BuildDictionary()); |
| 1336 } |
| 1337 |
| 1338 return list; |
| 1339 } |
| 1340 |
| 1341 void InternetOptionsHandler::FillNetworkInfo(DictionaryValue* dictionary) { |
| 1342 dictionary->SetBoolean("accessLocked", cros_->IsLocked()); |
| 1343 dictionary->Set("wiredList", GetWiredList()); |
| 1344 dictionary->Set("wirelessList", GetWirelessList()); |
| 1345 dictionary->Set("vpnList", GetVPNList()); |
| 1346 dictionary->Set("rememberedList", GetRememberedList()); |
| 1347 dictionary->SetBoolean("wifiAvailable", cros_->wifi_available()); |
| 1348 dictionary->SetBoolean("wifiBusy", cros_->wifi_busy()); |
| 1349 dictionary->SetBoolean("wifiEnabled", cros_->wifi_enabled()); |
| 1350 dictionary->SetBoolean("cellularAvailable", cros_->cellular_available()); |
| 1351 dictionary->SetBoolean("cellularBusy", cros_->cellular_busy()); |
| 1352 dictionary->SetBoolean("cellularEnabled", cros_->cellular_enabled()); |
| 1353 } |
| 1354 |
| 1355 void InternetOptionsHandler::SetValueDictionary( |
| 1356 DictionaryValue* settings, |
| 1357 const char* key, |
| 1358 base::Value* value, |
| 1359 const chromeos::NetworkPropertyUIData& ui_data) { |
| 1360 DictionaryValue* value_dict = new DictionaryValue(); |
| 1361 // DictionaryValue::Set() takes ownership of |value|. |
| 1362 if (value) |
| 1363 value_dict->Set("value", value); |
| 1364 const base::Value* default_value = ui_data.default_value(); |
| 1365 if (default_value) |
| 1366 value_dict->Set("default", default_value->DeepCopy()); |
| 1367 if (ui_data.managed()) |
| 1368 value_dict->SetString("controlledBy", "policy"); |
| 1369 else if (ui_data.recommended()) |
| 1370 value_dict->SetString("controlledBy", "recommended"); |
| 1371 settings->Set(key, value_dict); |
| 1372 } |
OLD | NEW |