NaCl: Update revision in DEPS, r12770 -> r12773
[chromium-blink-merge.git] / chrome / browser / ui / webui / options / chromeos / internet_options_handler.cc
blob80f21929907b9cc7e7b8d6a431b3b9cd0772596c
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.
5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
7 #include <ctype.h>
9 #include <map>
10 #include <string>
11 #include <vector>
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_window.h"
46 #include "chrome/browser/ui/host_desktop.h"
47 #include "chrome/browser/ui/scoped_tabbed_browser_displayer.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"
87 namespace chromeos {
88 namespace options {
90 namespace {
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.
94 const char kNetworkInfoKeyConnectable[] = "connectable";
95 const char kNetworkInfoKeyConnected[] = "connected";
96 const char kNetworkInfoKeyConnecting[] = "connecting";
97 const char kNetworkInfoKeyIconURL[] = "iconURL";
98 const char kNetworkInfoKeyNetworkName[] = "networkName";
99 const char kNetworkInfoKeyNetworkType[] = "networkType";
100 const char kNetworkInfoKeyServicePath[] = "servicePath";
101 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged";
103 // These are keys for getting IP information from the web ui.
104 const char kIpConfigAddress[] = "address";
105 const char kIpConfigPrefixLength[] = "prefixLength";
106 const char kIpConfigNetmask[] = "netmask";
107 const char kIpConfigGateway[] = "gateway";
108 const char kIpConfigNameServers[] = "nameServers";
109 const char kIpConfigAutoConfig[] = "ipAutoConfig";
110 const char kIpConfigWebProxyAutoDiscoveryUrl[] = "webProxyAutoDiscoveryUrl";
112 // These are types of name server selections from the web ui.
113 const char kNameServerTypeAutomatic[] = "automatic";
114 const char kNameServerTypeGoogle[] = "google";
115 const char kNameServerTypeUser[] = "user";
117 // These are dictionary names used to send data to the web ui.
118 const char kDictionaryIpConfig[] = "ipconfig";
119 const char kDictionaryStaticIp[] = "staticIP";
120 const char kDictionarySavedIp[] = "savedIP";
122 // Google public name servers (DNS).
123 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8";
125 // Functions we call in JavaScript.
126 const char kRefreshNetworkDataFunction[] =
127 "options.network.NetworkList.refreshNetworkData";
128 const char kSetDefaultNetworkIconsFunction[] =
129 "options.network.NetworkList.setDefaultNetworkIcons";
130 const char kShowDetailedInfoFunction[] =
131 "options.internet.DetailsInternetPage.showDetailedInfo";
132 const char kUpdateConnectionDataFunction[] =
133 "options.internet.DetailsInternetPage.updateConnectionData";
134 const char kUpdateCarrierFunction[] =
135 "options.internet.DetailsInternetPage.updateCarrier";
136 const char kUpdateLoggedInUserTypeFunction[] =
137 "options.network.NetworkList.updateLoggedInUserType";
138 const char kUpdateSecurityTabFunction[] =
139 "options.internet.DetailsInternetPage.updateSecurityTab";
141 // These are used to register message handlers with JavaScript.
142 const char kBuyDataPlanMessage[] = "buyDataPlan";
143 const char kChangePinMessage[] = "changePin";
144 const char kDisableCellularMessage[] = "disableCellular";
145 const char kDisableWifiMessage[] = "disableWifi";
146 const char kDisableWimaxMessage[] = "disableWimax";
147 const char kEnableCellularMessage[] = "enableCellular";
148 const char kEnableWifiMessage[] = "enableWifi";
149 const char kEnableWimaxMessage[] = "enableWimax";
150 const char kNetworkCommandMessage[] = "networkCommand";
151 const char kRefreshNetworksMessage[] = "refreshNetworks";
152 const char kSetApnMessage[] = "setApn";
153 const char kSetAutoConnectMessage[] = "setAutoConnect";
154 const char kSetCarrierMessage[] = "setCarrier";
155 const char kSetIPConfigMessage[] = "setIPConfig";
156 const char kSetPreferNetworkMessage[] = "setPreferNetwork";
157 const char kSetServerHostname[] = "setServerHostname";
158 const char kSetSimCardLockMessage[] = "setSimCardLock";
159 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo";
161 // These are strings used to communicate with JavaScript.
162 const char kTagActivate[] = "activate";
163 const char kTagActivationState[] = "activationState";
164 const char kTagAddConnection[] = "add";
165 const char kTagApn[] = "apn";
166 const char kTagAutoConnect[] = "autoConnect";
167 const char kTagBssid[] = "bssid";
168 const char kTagCarrierSelectFlag[] = "showCarrierSelect";
169 const char kTagCarrierUrl[] = "carrierUrl";
170 const char kTagCellular[] = "cellular";
171 const char kTagCellularAvailable[] = "cellularAvailable";
172 const char kTagCellularEnabled[] = "cellularEnabled";
173 const char kTagCellularSupportsScan[] = "cellularSupportsScan";
174 const char kTagConfigure[] = "configure";
175 const char kTagConnect[] = "connect";
176 const char kTagConnected[] = "connected";
177 const char kTagConnecting[] = "connecting";
178 const char kTagConnectionState[] = "connectionState";
179 const char kTagControlledBy[] = "controlledBy";
180 const char kTagDeviceConnected[] = "deviceConnected";
181 const char kTagDisableConnectButton[] = "disableConnectButton";
182 const char kTagDisconnect[] = "disconnect";
183 const char kTagEncryption[] = "encryption";
184 const char kTagErrorState[] = "errorState";
185 const char kTagEsn[] = "esn";
186 const char kTagFirmwareRevision[] = "firmwareRevision";
187 const char kTagForget[] = "forget";
188 const char kTagFrequency[] = "frequency";
189 const char kTagGsm[] = "gsm";
190 const char kTagHardwareAddress[] = "hardwareAddress";
191 const char kTagHardwareRevision[] = "hardwareRevision";
192 const char kTagIdentity[] = "identity";
193 const char kTagIccid[] = "iccid";
194 const char kTagImei[] = "imei";
195 const char kTagImsi[] = "imsi";
196 const char kTagLanguage[] = "language";
197 const char kTagLastGoodApn[] = "lastGoodApn";
198 const char kTagLocalizedName[] = "localizedName";
199 const char kTagManufacturer[] = "manufacturer";
200 const char kTagMdn[] = "mdn";
201 const char kTagMeid[] = "meid";
202 const char kTagMin[] = "min";
203 const char kTagModelId[] = "modelId";
204 const char kTagName[] = "name";
205 const char kTagNameServersGoogle[] = "nameServersGoogle";
206 const char kTagNameServerType[] = "nameServerType";
207 const char kTagNetworkId[] = "networkId";
208 const char kTagNetworkName[] = "networkName";
209 const char kTagNetworkTechnology[] = "networkTechnology";
210 const char kTagOperatorCode[] = "operatorCode";
211 const char kTagOperatorName[] = "operatorName";
212 const char kTagOptions[] = "options";
213 const char kTagPassword[] = "password";
214 const char kTagPolicy[] = "policy";
215 const char kTagPreferred[] = "preferred";
216 const char kTagPrlVersion[] = "prlVersion";
217 const char kTagProviderType[] = "providerType";
218 const char kTagProviderApnList[] = "providerApnList";
219 const char kTagRecommended[] = "recommended";
220 const char kTagRecommendedValue[] = "recommendedValue";
221 const char kTagRemembered[] = "remembered";
222 const char kTagRememberedList[] = "rememberedList";
223 const char kTagRestrictedPool[] = "restrictedPool";
224 const char kTagRoamingState[] = "roamingState";
225 const char kTagServerHostname[] = "serverHostname";
226 const char kTagCarriers[] = "carriers";
227 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
228 const char kTagServiceName[] = "serviceName";
229 const char kTagServicePath[] = "servicePath";
230 const char kTagShared[] = "shared";
231 const char kTagShowActivateButton[] = "showActivateButton";
232 const char kTagShowPreferred[] = "showPreferred";
233 const char kTagShowProxy[] = "showProxy";
234 const char kTagShowStaticIPConfig[] = "showStaticIPConfig";
235 const char kTagShowViewAccountButton[] = "showViewAccountButton";
236 const char kTagSimCardLockEnabled[] = "simCardLockEnabled";
237 const char kTagSsid[] = "ssid";
238 const char kTagStrength[] = "strength";
239 const char kTagSupportUrl[] = "supportUrl";
240 const char kTagTrue[] = "true";
241 const char kTagType[] = "type";
242 const char kTagUsername[] = "username";
243 const char kTagValue[] = "value";
244 const char kTagVpn[] = "vpn";
245 const char kTagVpnList[] = "vpnList";
246 const char kTagWifi[] = "wifi";
247 const char kTagWifiAvailable[] = "wifiAvailable";
248 const char kTagWifiEnabled[] = "wifiEnabled";
249 const char kTagWimaxAvailable[] = "wimaxAvailable";
250 const char kTagWimaxEnabled[] = "wimaxEnabled";
251 const char kTagWiredList[] = "wiredList";
252 const char kTagWirelessList[] = "wirelessList";
254 const int kPreferredPriority = 1;
256 void 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);
268 const NetworkState* GetNetworkState(const std::string& service_path) {
269 return NetworkHandler::Get()->network_state_handler()->
270 GetNetworkState(service_path);
273 void 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"));
285 std::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);
300 std::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);
311 std::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);
340 std::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 "";
364 std::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;
388 return "Unknown";
391 std::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;
408 return l10n_util::GetStringUTF8(id);
411 bool HasPolicyForFavorite(const FavoriteState* favorite,
412 const PrefService* profile_prefs) {
413 return onc::HasPolicyForFavoriteNetwork(
414 profile_prefs, g_browser_process->local_state(), *favorite);
417 bool 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);
427 void 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);
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());
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.
448 base::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));
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();
467 base::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));
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();
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.
489 base::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;
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++;
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++;
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++;
533 if (routing_parameters_set)
534 *routing_parameters_set = routing_parameters;
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;
543 return ip_info_dict.release();
546 bool CanForgetNetworkType(const std::string& type) {
547 return type == shill::kTypeWifi ||
548 type == shill::kTypeWimax ||
549 type == shill::kTypeVPN;
552 bool CanAddNetworkType(const std::string& type) {
553 return type == shill::kTypeWifi ||
554 type == shill::kTypeVPN ||
555 type == shill::kTypeCellular;
558 // Decorate dictionary |value_dict| with policy information from |ui_data|.
559 void 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);
568 if (recommended_value)
569 value_dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
572 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and
573 // store it under |key| in |settings|. Takes ownership of |value|.
574 void 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);
585 // Creates a decorated dictionary like SetValueDictionary does, but extended for
586 // the Autoconnect property, which respects additionally global network policy.
587 void 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;
608 DecorateValueDictionary(ui_data, *value, dict);
611 std::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;
621 void 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);
637 // Fills |dictionary| with the configuration details of |vpn|. |onc| is required
638 // for augmenting the policy-managed information.
639 void 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;
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));
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);
665 dictionary->SetString(kTagUsername, username);
667 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
668 const base::DictionaryValue* onc =
669 onc::FindPolicyForActiveUser(vpn->guid(), &onc_source);
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);
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);
691 // Given a list of supported carrier's by the device, return the index of
692 // the carrier the device is currently using.
693 int 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;
712 return -1;
715 void PopulateWifiDetails(const NetworkState* wifi,
716 const base::DictionaryValue& shill_properties,
717 base::DictionaryValue* dictionary);
718 // TODO(stevenjb): Move implementation here.
720 void PopulateWimaxDetails(const NetworkState* wimax,
721 const base::DictionaryValue& shill_properties,
722 base::DictionaryValue* dictionary);
723 // TODO(stevenjb): Move implementation here.
725 void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
726 base::DictionaryValue* dictionary);
727 // TODO(stevenjb): Move implementation here.
729 void PopulateCellularDetails(const NetworkState* cellular,
730 const base::DictionaryValue& shill_properties,
731 base::DictionaryValue* dictionary);
732 // TODO(stevenjb): Move implementation here.
734 void PopulateConnectionDetails(const NetworkState* network,
735 const base::DictionaryValue& shill_properties,
736 base::DictionaryValue* dictionary);
737 // TODO(stevenjb): Move implementation here.
739 // Helper methods for SetIPConfigProperties
740 bool 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;
747 return false;
750 bool 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;
760 return false;
763 bool 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;
773 return false;
776 void 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"));
785 } // namespace
787 InternetOptionsHandler::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);
797 InternetOptionsHandler::~InternetOptionsHandler() {
798 if (NetworkHandler::IsInitialized()) {
799 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
800 this, FROM_HERE);
802 if (LoginState::Get()->IsInitialized())
803 LoginState::Get()->RemoveObserver(this);
806 void InternetOptionsHandler::GetLocalizedValues(
807 base::DictionaryValue* localized_strings) {
808 DCHECK(localized_strings);
810 static OptionsStringResource resources[] = {
812 // Main settings page.
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 },
844 // Internet details dialog.
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 },
882 // Wifi Tab.
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 },
911 // VPN Tab.
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 },
921 // Cellular Tab.
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 },
952 // Security Tab.
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 },
960 // Proxy Tab.
961 { "webProxyAutoDiscoveryUrl", IDS_PROXY_WEB_PROXY_AUTO_DISCOVERY },
964 RegisterStrings(localized_strings, resources, arraysize(resources));
966 std::string owner;
967 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
968 localized_strings->SetString("ownerUserId", base::UTF8ToUTF16(owner));
970 base::DictionaryValue* network_dictionary = new base::DictionaryValue;
971 FillNetworkInfo(network_dictionary);
972 localized_strings->Set("networkData", network_dictionary);
975 void 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();
990 void 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)));
1048 void InternetOptionsHandler::EnableWifiCallback(const base::ListValue* args) {
1049 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1050 NetworkTypePattern::WiFi(), true,
1051 base::Bind(&ShillError, "EnableWifiCallback"));
1054 void InternetOptionsHandler::DisableWifiCallback(const base::ListValue* args) {
1055 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1056 NetworkTypePattern::WiFi(), false,
1057 base::Bind(&ShillError, "DisableWifiCallback"));
1060 void 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;
1069 if (!device->sim_lock_type().empty()) {
1070 SimDialogDelegate::ShowDialog(GetNativeWindow(),
1071 SimDialogDelegate::SIM_DIALOG_UNLOCK);
1072 return;
1074 if (!handler->IsTechnologyEnabled(NetworkTypePattern::Cellular())) {
1075 handler->SetTechnologyEnabled(
1076 NetworkTypePattern::Cellular(), true,
1077 base::Bind(&ShillError, "EnableCellularCallback"));
1078 return;
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 // The mobile device will be managed by the primary user.
1089 chrome::ScopedTabbedBrowserDisplayer displayer(
1090 ProfileManager::GetPrimaryUserProfile(),
1091 chrome::HOST_DESKTOP_TYPE_ASH);
1092 chrome::ShowSingletonTab(displayer.browser(), GURL(setup_url));
1093 return;
1097 // TODO(nkostylev): Show generic error message. http://crosbug.com/15444
1099 LOG(ERROR) << "EnableCellularCallback called for enabled mobile device";
1102 void InternetOptionsHandler::DisableCellularCallback(
1103 const base::ListValue* args) {
1104 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1105 NetworkTypePattern::Mobile(), false,
1106 base::Bind(&ShillError, "DisableCellularCallback"));
1109 void InternetOptionsHandler::EnableWimaxCallback(const base::ListValue* args) {
1110 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1111 NetworkTypePattern::Wimax(), true,
1112 base::Bind(&ShillError, "EnableWimaxCallback"));
1115 void InternetOptionsHandler::DisableWimaxCallback(const base::ListValue* args) {
1116 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1117 NetworkTypePattern::Wimax(), false,
1118 base::Bind(&ShillError, "DisableWimaxCallback"));
1121 void InternetOptionsHandler::ShowMorePlanInfoCallback(
1122 const base::ListValue* args) {
1123 if (!web_ui())
1124 return;
1125 std::string service_path;
1126 if (args->GetSize() != 1 || !args->GetString(0, &service_path)) {
1127 NOTREACHED();
1128 return;
1130 ash::network_connect::ShowMobileSetup(service_path);
1133 void InternetOptionsHandler::BuyDataPlanCallback(const base::ListValue* args) {
1134 if (!web_ui())
1135 return;
1136 std::string service_path;
1137 if (args->GetSize() != 1 || !args->GetString(0, &service_path)) {
1138 NOTREACHED();
1139 return;
1141 ash::network_connect::ShowMobileSetup(service_path);
1144 void InternetOptionsHandler::SetApnCallback(const base::ListValue* args) {
1145 std::string service_path;
1146 if (!args->GetString(0, &service_path)) {
1147 NOTREACHED();
1148 return;
1150 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1151 service_path,
1152 base::Bind(&InternetOptionsHandler::SetApnProperties,
1153 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())),
1154 base::Bind(&ShillError, "SetApnCallback"));
1157 void InternetOptionsHandler::SetApnProperties(
1158 const base::ListValue* args,
1159 const std::string& service_path,
1160 const base::DictionaryValue& shill_properties) {
1161 std::string apn, username, password;
1162 if (!args->GetString(1, &apn) ||
1163 !args->GetString(2, &username) ||
1164 !args->GetString(3, &password)) {
1165 NOTREACHED();
1166 return;
1168 NET_LOG_EVENT("SetApnCallback", service_path);
1170 if (apn.empty()) {
1171 std::vector<std::string> properties_to_clear;
1172 properties_to_clear.push_back(shill::kCellularApnProperty);
1173 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
1174 service_path, properties_to_clear,
1175 base::Bind(&base::DoNothing),
1176 base::Bind(&ShillError, "ClearCellularApnProperties"));
1177 return;
1180 const base::DictionaryValue* shill_apn_dict = NULL;
1181 std::string network_id;
1182 if (shill_properties.GetDictionaryWithoutPathExpansion(
1183 shill::kCellularApnProperty, &shill_apn_dict)) {
1184 shill_apn_dict->GetStringWithoutPathExpansion(
1185 shill::kApnNetworkIdProperty, &network_id);
1187 base::DictionaryValue properties;
1188 base::DictionaryValue* apn_dict = new base::DictionaryValue;
1189 apn_dict->SetStringWithoutPathExpansion(shill::kApnProperty, apn);
1190 apn_dict->SetStringWithoutPathExpansion(shill::kApnNetworkIdProperty,
1191 network_id);
1192 apn_dict->SetStringWithoutPathExpansion(shill::kApnUsernameProperty,
1193 username);
1194 apn_dict->SetStringWithoutPathExpansion(shill::kApnPasswordProperty,
1195 password);
1196 properties.SetWithoutPathExpansion(shill::kCellularApnProperty, apn_dict);
1197 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
1198 service_path, properties,
1199 base::Bind(&base::DoNothing),
1200 base::Bind(&ShillError, "SetApnProperties"));
1203 void InternetOptionsHandler::CarrierStatusCallback() {
1204 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
1205 const DeviceState* device =
1206 handler->GetDeviceStateByType(NetworkTypePattern::Cellular());
1207 if (device && (device->carrier() == shill::kCarrierSprint)) {
1208 const NetworkState* network =
1209 handler->FirstNetworkByType(NetworkTypePattern::Cellular());
1210 if (network) {
1211 ash::network_connect::ActivateCellular(network->path());
1212 UpdateConnectionData(network->path());
1215 UpdateCarrier();
1218 void InternetOptionsHandler::SetCarrierCallback(const base::ListValue* args) {
1219 std::string service_path;
1220 std::string carrier;
1221 if (args->GetSize() != 2 ||
1222 !args->GetString(0, &service_path) ||
1223 !args->GetString(1, &carrier)) {
1224 NOTREACHED();
1225 return;
1227 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
1228 GetDeviceStateByType(NetworkTypePattern::Cellular());
1229 if (!device) {
1230 LOG(WARNING) << "SetCarrierCallback with no cellular device.";
1231 return;
1233 NetworkHandler::Get()->network_device_handler()->SetCarrier(
1234 device->path(),
1235 carrier,
1236 base::Bind(&InternetOptionsHandler::CarrierStatusCallback,
1237 weak_factory_.GetWeakPtr()),
1238 base::Bind(&ShillError, "SetCarrierCallback"));
1241 void InternetOptionsHandler::SetSimCardLockCallback(
1242 const base::ListValue* args) {
1243 bool require_pin_new_value;
1244 if (!args->GetBoolean(0, &require_pin_new_value)) {
1245 NOTREACHED();
1246 return;
1248 // 1. Bring up SIM unlock dialog, pass new RequirePin setting in URL.
1249 // 2. Dialog will ask for current PIN in any case.
1250 // 3. If card is locked it will first call PIN unlock operation
1251 // 4. Then it will call Set RequirePin, passing the same PIN.
1252 // 5. We'll get notified by REQUIRE_PIN_SETTING_CHANGE_ENDED notification.
1253 SimDialogDelegate::SimDialogMode mode;
1254 if (require_pin_new_value)
1255 mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON;
1256 else
1257 mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF;
1258 SimDialogDelegate::ShowDialog(GetNativeWindow(), mode);
1261 void InternetOptionsHandler::ChangePinCallback(const base::ListValue* args) {
1262 SimDialogDelegate::ShowDialog(GetNativeWindow(),
1263 SimDialogDelegate::SIM_DIALOG_CHANGE_PIN);
1266 void InternetOptionsHandler::RefreshNetworksCallback(
1267 const base::ListValue* args) {
1268 NetworkHandler::Get()->network_state_handler()->RequestScan();
1271 std::string InternetOptionsHandler::GetIconDataUrl(int resource_id) const {
1272 gfx::ImageSkia* icon =
1273 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
1274 gfx::ImageSkiaRep image_rep = icon->GetRepresentation(
1275 ui::GetImageScale(web_ui()->GetDeviceScaleFactor()));
1276 return webui::GetBitmapDataUrl(image_rep.sk_bitmap());
1279 void InternetOptionsHandler::RefreshNetworkData() {
1280 base::DictionaryValue dictionary;
1281 FillNetworkInfo(&dictionary);
1282 web_ui()->CallJavascriptFunction(
1283 kRefreshNetworkDataFunction, dictionary);
1286 void InternetOptionsHandler::UpdateConnectionData(
1287 const std::string& service_path) {
1288 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1289 service_path,
1290 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback,
1291 weak_factory_.GetWeakPtr()),
1292 base::Bind(&ShillError, "UpdateConnectionData"));
1295 void InternetOptionsHandler::UpdateConnectionDataCallback(
1296 const std::string& service_path,
1297 const base::DictionaryValue& shill_properties) {
1298 const NetworkState* network = GetNetworkState(service_path);
1299 if (!network)
1300 return;
1301 base::DictionaryValue dictionary;
1302 PopulateConnectionDetails(network, shill_properties, &dictionary);
1303 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, dictionary);
1306 void InternetOptionsHandler::UpdateCarrier() {
1307 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction);
1310 void InternetOptionsHandler::DeviceListChanged() {
1311 if (!web_ui())
1312 return;
1313 RefreshNetworkData();
1316 void InternetOptionsHandler::NetworkListChanged() {
1317 if (!web_ui())
1318 return;
1319 RefreshNetworkData();
1322 void InternetOptionsHandler::NetworkConnectionStateChanged(
1323 const NetworkState* network) {
1324 if (!web_ui())
1325 return;
1326 // Update the connection data for the detailed view when the connection state
1327 // of any network changes.
1328 if (!details_path_.empty())
1329 UpdateConnectionData(details_path_);
1332 void InternetOptionsHandler::NetworkPropertiesUpdated(
1333 const NetworkState* network) {
1334 if (!web_ui())
1335 return;
1336 RefreshNetworkData();
1337 UpdateConnectionData(network->path());
1340 void InternetOptionsHandler::LoggedInStateChanged() {
1341 UpdateLoggedInUserType();
1344 void InternetOptionsHandler::UpdateLoggedInUserType() {
1345 if (!web_ui())
1346 return;
1347 base::StringValue login_type(
1348 LoggedInUserTypeToString(LoginState::Get()->GetLoggedInUserType()));
1349 web_ui()->CallJavascriptFunction(
1350 kUpdateLoggedInUserTypeFunction, login_type);
1353 void InternetOptionsHandler::Observe(
1354 int type,
1355 const content::NotificationSource& source,
1356 const content::NotificationDetails& details) {
1357 if (type == chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED) {
1358 base::FundamentalValue require_pin(*content::Details<bool>(details).ptr());
1359 web_ui()->CallJavascriptFunction(
1360 kUpdateSecurityTabFunction, require_pin);
1361 } else if (type == chrome::NOTIFICATION_ENTER_PIN_ENDED) {
1362 // We make an assumption (which is valid for now) that the SIM
1363 // unlock dialog is put up only when the user is trying to enable
1364 // mobile data.
1365 bool cancelled = *content::Details<bool>(details).ptr();
1366 if (cancelled)
1367 RefreshNetworkData();
1368 // The case in which the correct PIN was entered and the SIM is
1369 // now unlocked is handled in NetworkMenuButton.
1373 void InternetOptionsHandler::SetServerHostnameCallback(
1374 const base::ListValue* args) {
1375 std::string service_path, server_hostname;
1376 if (args->GetSize() < 2 ||
1377 !args->GetString(0, &service_path) ||
1378 !args->GetString(1, &server_hostname)) {
1379 NOTREACHED();
1380 return;
1382 SetNetworkProperty(service_path, shill::kProviderHostProperty,
1383 base::Value::CreateStringValue(server_hostname));
1386 void InternetOptionsHandler::SetPreferNetworkCallback(
1387 const base::ListValue* args) {
1388 std::string service_path, prefer_network_str;
1389 if (args->GetSize() < 2 ||
1390 !args->GetString(0, &service_path) ||
1391 !args->GetString(1, &prefer_network_str)) {
1392 NOTREACHED();
1393 return;
1395 int priority = (prefer_network_str == kTagTrue) ? kPreferredPriority : 0;
1396 SetNetworkProperty(service_path, shill::kPriorityProperty,
1397 base::Value::CreateIntegerValue(priority));
1400 void InternetOptionsHandler::SetAutoConnectCallback(
1401 const base::ListValue* args) {
1402 std::string service_path, auto_connect_str;
1403 if (args->GetSize() < 2 ||
1404 !args->GetString(0, &service_path) ||
1405 !args->GetString(1, &auto_connect_str)) {
1406 NOTREACHED();
1407 return;
1409 bool auto_connect = auto_connect_str == kTagTrue;
1410 SetNetworkProperty(service_path, shill::kAutoConnectProperty,
1411 base::Value::CreateBooleanValue(auto_connect));
1414 void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) {
1415 std::string service_path;
1416 if (!args->GetString(0, &service_path)) {
1417 NOTREACHED();
1418 return;
1420 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1421 service_path,
1422 base::Bind(&InternetOptionsHandler::SetIPConfigProperties,
1423 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())),
1424 base::Bind(&ShillError, "SetIPConfigCallback"));
1427 void InternetOptionsHandler::SetIPConfigProperties(
1428 const base::ListValue* args,
1429 const std::string& service_path,
1430 const base::DictionaryValue& shill_properties) {
1431 std::string address, netmask, gateway, name_server_type, name_servers;
1432 bool dhcp_for_ip;
1433 if (!args->GetBoolean(1, &dhcp_for_ip) ||
1434 !args->GetString(2, &address) ||
1435 !args->GetString(3, &netmask) ||
1436 !args->GetString(4, &gateway) ||
1437 !args->GetString(5, &name_server_type) ||
1438 !args->GetString(6, &name_servers)) {
1439 NOTREACHED();
1440 return;
1442 NET_LOG_USER("SetIPConfigProperties", service_path);
1444 bool request_reconnect = false;
1445 std::vector<std::string> properties_to_clear;
1446 base::DictionaryValue properties_to_set;
1448 if (dhcp_for_ip) {
1449 request_reconnect |= AppendPropertyKeyIfPresent(
1450 shill::kStaticIPAddressProperty,
1451 shill_properties, &properties_to_clear);
1452 request_reconnect |= AppendPropertyKeyIfPresent(
1453 shill::kStaticIPPrefixlenProperty,
1454 shill_properties, &properties_to_clear);
1455 request_reconnect |= AppendPropertyKeyIfPresent(
1456 shill::kStaticIPGatewayProperty,
1457 shill_properties, &properties_to_clear);
1458 } else {
1459 request_reconnect |= AddStringPropertyIfChanged(
1460 shill::kStaticIPAddressProperty,
1461 address, shill_properties, &properties_to_set);
1462 int prefixlen = network_util::NetmaskToPrefixLength(netmask);
1463 if (prefixlen < 0) {
1464 LOG(ERROR) << "Invalid prefix length for: " << service_path
1465 << " with netmask " << netmask;
1466 prefixlen = 0;
1468 request_reconnect |= AddIntegerPropertyIfChanged(
1469 shill::kStaticIPPrefixlenProperty,
1470 prefixlen, shill_properties, &properties_to_set);
1471 request_reconnect |= AddStringPropertyIfChanged(
1472 shill::kStaticIPGatewayProperty,
1473 gateway, shill_properties, &properties_to_set);
1476 if (name_server_type == kNameServerTypeAutomatic) {
1477 AppendPropertyKeyIfPresent(shill::kStaticIPNameServersProperty,
1478 shill_properties, &properties_to_clear);
1479 } else {
1480 if (name_server_type == kNameServerTypeGoogle)
1481 name_servers = kGoogleNameServers;
1482 AddStringPropertyIfChanged(
1483 shill::kStaticIPNameServersProperty,
1484 name_servers, shill_properties, &properties_to_set);
1487 if (!properties_to_clear.empty()) {
1488 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
1489 service_path, properties_to_clear,
1490 base::Bind(&base::DoNothing),
1491 base::Bind(&ShillError, "ClearIPConfigProperties"));
1493 if (!properties_to_set.empty()) {
1494 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
1495 service_path, properties_to_set,
1496 base::Bind(&base::DoNothing),
1497 base::Bind(&ShillError, "SetIPConfigProperties"));
1499 std::string device_path;
1500 shill_properties.GetStringWithoutPathExpansion(
1501 shill::kDeviceProperty, &device_path);
1502 if (!device_path.empty()) {
1503 base::Closure callback = base::Bind(&base::DoNothing);
1504 // If auto config or a static IP property changed, we need to reconnect
1505 // to the network.
1506 if (request_reconnect)
1507 callback = base::Bind(&RequestReconnect, service_path, GetNativeWindow());
1508 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs(
1509 device_path,
1510 callback,
1511 base::Bind(&ShillError, "RequestRefreshIPConfigs"));
1515 void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
1516 const std::string& service_path,
1517 const base::DictionaryValue& shill_properties) {
1518 const NetworkState* network = GetNetworkState(service_path);
1519 if (!network) {
1520 LOG(ERROR) << "Network properties not found: " << service_path;
1521 return;
1524 details_path_ = service_path;
1526 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
1527 const base::DictionaryValue* onc =
1528 onc::FindPolicyForActiveUser(network->guid(), &onc_source);
1529 const NetworkPropertyUIData property_ui_data(onc_source);
1531 base::DictionaryValue dictionary;
1533 // Device hardware address
1534 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
1535 GetDeviceState(network->device_path());
1536 if (device)
1537 dictionary.SetString(kTagHardwareAddress, device->GetFormattedMacAddress());
1539 // IP config
1540 scoped_ptr<base::DictionaryValue> ipconfig_dhcp(new base::DictionaryValue);
1541 ipconfig_dhcp->SetString(kIpConfigAddress, network->ip_address());
1542 ipconfig_dhcp->SetString(kIpConfigNetmask, network->GetNetmask());
1543 ipconfig_dhcp->SetString(kIpConfigGateway, network->gateway());
1544 std::string ipconfig_name_servers = network->GetDnsServersAsString();
1545 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers);
1546 ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl,
1547 network->web_proxy_auto_discovery_url().spec());
1548 SetValueDictionary(&dictionary,
1549 kDictionaryIpConfig,
1550 ipconfig_dhcp.release(),
1551 property_ui_data);
1553 std::string name_server_type = kNameServerTypeAutomatic;
1554 int automatic_ip_config = 0;
1555 scoped_ptr<base::DictionaryValue> static_ip_dict(
1556 BuildIPInfoDictionary(shill_properties, true, &automatic_ip_config));
1557 dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0);
1558 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0)
1559 << "UI doesn't support automatic specification of individual "
1560 << "static IP parameters.";
1561 scoped_ptr<base::DictionaryValue> saved_ip_dict(
1562 BuildIPInfoDictionary(shill_properties, false, NULL));
1563 dictionary.Set(kDictionarySavedIp, saved_ip_dict.release());
1565 // Determine what kind of name server setting we have by comparing the
1566 // StaticIP and Google values with the ipconfig values.
1567 std::string static_ip_nameservers;
1568 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers);
1569 if (!static_ip_nameservers.empty() &&
1570 static_ip_nameservers == ipconfig_name_servers) {
1571 name_server_type = kNameServerTypeUser;
1573 if (ipconfig_name_servers == kGoogleNameServers) {
1574 name_server_type = kNameServerTypeGoogle;
1576 SetValueDictionary(&dictionary,
1577 kDictionaryStaticIp,
1578 static_ip_dict.release(),
1579 property_ui_data);
1581 std::string type = network->type();
1582 dictionary.SetString(kTagType, type);
1583 dictionary.SetString(kTagServicePath, network->path());
1584 dictionary.SetString(kTagNameServerType, name_server_type);
1585 dictionary.SetString(kTagNameServersGoogle, kGoogleNameServers);
1587 // Only show proxy for remembered networks.
1588 dictionary.SetBoolean(kTagShowProxy, !network->profile_path().empty());
1590 // Enable static ip config for Ethernet or WiFi.
1591 bool staticIPConfig = network->Matches(NetworkTypePattern::Ethernet()) ||
1592 type == shill::kTypeWifi;
1593 dictionary.SetBoolean(kTagShowStaticIPConfig, staticIPConfig);
1595 dictionary.SetBoolean(kTagShowPreferred, !network->profile_path().empty());
1596 int priority = 0;
1597 shill_properties.GetIntegerWithoutPathExpansion(
1598 shill::kPriorityProperty, &priority);
1599 bool preferred = priority > 0;
1600 SetValueDictionary(&dictionary, kTagPreferred,
1601 new base::FundamentalValue(preferred),
1602 property_ui_data);
1604 NetworkPropertyUIData auto_connect_ui_data(onc_source);
1605 std::string onc_path_to_auto_connect;
1606 if (type == shill::kTypeWifi) {
1607 onc_path_to_auto_connect = base::StringPrintf(
1608 "%s.%s",
1609 ::onc::network_config::kWiFi,
1610 ::onc::wifi::kAutoConnect);
1611 } else if (type == shill::kTypeVPN) {
1612 onc_path_to_auto_connect = base::StringPrintf(
1613 "%s.%s",
1614 ::onc::network_config::kVPN,
1615 ::onc::vpn::kAutoConnect);
1617 if (!onc_path_to_auto_connect.empty()) {
1618 auto_connect_ui_data.ParseOncProperty(
1619 onc_source, onc, onc_path_to_auto_connect);
1621 bool auto_connect = false;
1622 shill_properties.GetBooleanWithoutPathExpansion(
1623 shill::kAutoConnectProperty, &auto_connect);
1624 SetAutoconnectValueDictionary(network->IsPrivate(),
1625 onc_source,
1626 auto_connect,
1627 auto_connect_ui_data,
1628 &dictionary);
1630 PopulateConnectionDetails(network, shill_properties, &dictionary);
1632 // Show details dialog
1633 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, dictionary);
1636 namespace {
1638 void PopulateConnectionDetails(const NetworkState* network,
1639 const base::DictionaryValue& shill_properties,
1640 base::DictionaryValue* dictionary) {
1641 dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
1642 dictionary->SetString(kTagServiceName, network->name());
1643 dictionary->SetBoolean(kTagConnecting, network->IsConnectingState());
1644 dictionary->SetBoolean(kTagConnected, network->IsConnectedState());
1645 dictionary->SetString(kTagConnectionState,
1646 ConnectionStateString(network->connection_state()));
1647 dictionary->SetString(kTagNetworkName, network->name());
1648 dictionary->SetString(
1649 kTagErrorState,
1650 ash::network_connect::ErrorString(network->error(), network->path()));
1652 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty());
1653 bool shared = !network->IsPrivate();
1654 dictionary->SetBoolean(kTagShared, shared);
1656 const std::string& type = network->type();
1657 const NetworkState* connected_network =
1658 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
1659 NetworkTypePattern::Primitive(type));
1661 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
1663 if (type == shill::kTypeWifi)
1664 PopulateWifiDetails(network, shill_properties, dictionary);
1665 else if (type == shill::kTypeWimax)
1666 PopulateWimaxDetails(network, shill_properties, dictionary);
1667 else if (type == shill::kTypeCellular)
1668 PopulateCellularDetails(network, shill_properties, dictionary);
1669 else if (type == shill::kTypeVPN)
1670 PopulateVPNDetails(network, shill_properties, dictionary);
1673 void PopulateWifiDetails(const NetworkState* wifi,
1674 const base::DictionaryValue& shill_properties,
1675 base::DictionaryValue* dictionary) {
1676 dictionary->SetString(kTagSsid, wifi->name());
1677 dictionary->SetInteger(kTagStrength, wifi->signal_strength());
1678 dictionary->SetString(kTagEncryption,
1679 EncryptionString(wifi->security(), wifi->eap_method()));
1680 CopyStringFromDictionary(shill_properties, shill::kWifiBSsid,
1681 kTagBssid, dictionary);
1682 CopyIntegerFromDictionary(shill_properties, shill::kWifiFrequency,
1683 kTagFrequency, false, dictionary);
1686 void PopulateWimaxDetails(const NetworkState* wimax,
1687 const base::DictionaryValue& shill_properties,
1688 base::DictionaryValue* dictionary) {
1689 dictionary->SetInteger(kTagStrength, wimax->signal_strength());
1690 CopyStringFromDictionary(shill_properties, shill::kEapIdentityProperty,
1691 kTagIdentity, dictionary);
1694 void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
1695 base::DictionaryValue* dictionary) {
1696 CopyStringFromDictionary(*apn, shill::kApnProperty,
1697 kTagApn, dictionary);
1698 CopyStringFromDictionary(*apn, shill::kApnNetworkIdProperty,
1699 kTagNetworkId, dictionary);
1700 CopyStringFromDictionary(*apn, shill::kApnUsernameProperty,
1701 kTagUsername, dictionary);
1702 CopyStringFromDictionary(*apn, shill::kApnPasswordProperty,
1703 kTagPassword, dictionary);
1704 CopyStringFromDictionary(*apn, shill::kApnNameProperty,
1705 kTagName, dictionary);
1706 CopyStringFromDictionary(*apn, shill::kApnLocalizedNameProperty,
1707 kTagLocalizedName, dictionary);
1708 CopyStringFromDictionary(*apn, shill::kApnLanguageProperty,
1709 kTagLanguage, dictionary);
1712 void PopulateCellularDetails(const NetworkState* cellular,
1713 const base::DictionaryValue& shill_properties,
1714 base::DictionaryValue* dictionary) {
1715 dictionary->SetBoolean(kTagCarrierSelectFlag,
1716 CommandLine::ForCurrentProcess()->HasSwitch(
1717 chromeos::switches::kEnableCarrierSwitching));
1718 // Cellular network / connection settings.
1719 dictionary->SetString(kTagNetworkTechnology, cellular->network_technology());
1720 dictionary->SetString(kTagActivationState,
1721 ActivationStateString(cellular->activation_state()));
1722 dictionary->SetString(kTagRoamingState,
1723 RoamingStateString(cellular->roaming()));
1724 bool restricted = cellular->connection_state() == shill::kStatePortal;
1725 dictionary->SetString(kTagRestrictedPool,
1726 restricted ?
1727 l10n_util::GetStringUTF8(
1728 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) :
1729 l10n_util::GetStringUTF8(
1730 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL));
1732 const base::DictionaryValue* serving_operator = NULL;
1733 if (shill_properties.GetDictionaryWithoutPathExpansion(
1734 shill::kServingOperatorProperty, &serving_operator)) {
1735 CopyStringFromDictionary(*serving_operator, shill::kOperatorNameKey,
1736 kTagOperatorName, dictionary);
1737 CopyStringFromDictionary(*serving_operator, shill::kOperatorCodeKey,
1738 kTagOperatorCode, dictionary);
1741 const base::DictionaryValue* olp = NULL;
1742 if (shill_properties.GetDictionaryWithoutPathExpansion(
1743 shill::kPaymentPortalProperty, &olp)) {
1744 std::string url;
1745 olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url);
1746 dictionary->SetString(kTagSupportUrl, url);
1749 base::DictionaryValue* apn = new base::DictionaryValue;
1750 const base::DictionaryValue* source_apn = NULL;
1751 if (shill_properties.GetDictionaryWithoutPathExpansion(
1752 shill::kCellularApnProperty, &source_apn)) {
1753 CreateDictionaryFromCellularApn(source_apn, apn);
1755 dictionary->Set(kTagApn, apn);
1757 base::DictionaryValue* last_good_apn = new base::DictionaryValue;
1758 if (shill_properties.GetDictionaryWithoutPathExpansion(
1759 shill::kCellularLastGoodApnProperty, &source_apn)) {
1760 CreateDictionaryFromCellularApn(source_apn, last_good_apn);
1762 dictionary->Set(kTagLastGoodApn, last_good_apn);
1764 // These default to empty and are only set if device != NULL.
1765 std::string carrier_id;
1766 std::string mdn;
1768 // Device settings.
1769 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
1770 GetDeviceState(cellular->device_path());
1771 if (device) {
1772 // TODO(stevenjb): Add NetworkDeviceHandler::GetProperties() and use that
1773 // to retrieve the complete dictionary of device properties, instead of
1774 // caching them (will be done for the new UI).
1775 const base::DictionaryValue& device_properties = device->properties();
1776 const NetworkPropertyUIData cellular_property_ui_data(
1777 cellular->ui_data().onc_source());
1778 CopyStringFromDictionary(device_properties, shill::kManufacturerProperty,
1779 kTagManufacturer, dictionary);
1780 CopyStringFromDictionary(device_properties, shill::kModelIDProperty,
1781 kTagModelId, dictionary);
1782 CopyStringFromDictionary(device_properties,
1783 shill::kFirmwareRevisionProperty,
1784 kTagFirmwareRevision, dictionary);
1785 CopyStringFromDictionary(device_properties,
1786 shill::kHardwareRevisionProperty,
1787 kTagHardwareRevision, dictionary);
1788 CopyIntegerFromDictionary(device_properties, shill::kPRLVersionProperty,
1789 kTagPrlVersion, true, dictionary);
1790 CopyStringFromDictionary(device_properties, shill::kMeidProperty,
1791 kTagMeid, dictionary);
1792 CopyStringFromDictionary(device_properties, shill::kIccidProperty,
1793 kTagIccid, dictionary);
1794 CopyStringFromDictionary(device_properties, shill::kImeiProperty,
1795 kTagImei, dictionary);
1796 mdn = CopyStringFromDictionary(device_properties, shill::kMdnProperty,
1797 kTagMdn, dictionary);
1798 CopyStringFromDictionary(device_properties, shill::kImsiProperty,
1799 kTagImsi, dictionary);
1800 CopyStringFromDictionary(device_properties, shill::kEsnProperty,
1801 kTagEsn, dictionary);
1802 CopyStringFromDictionary(device_properties, shill::kMinProperty,
1803 kTagMin, dictionary);
1804 std::string family;
1805 device_properties.GetStringWithoutPathExpansion(
1806 shill::kTechnologyFamilyProperty, &family);
1807 dictionary->SetBoolean(kTagGsm, family == shill::kNetworkTechnologyGsm);
1809 SetValueDictionary(
1810 dictionary, kTagSimCardLockEnabled,
1811 new base::FundamentalValue(device->sim_lock_enabled()),
1812 cellular_property_ui_data);
1814 carrier_id = device->home_provider_id();
1816 MobileConfig* config = MobileConfig::GetInstance();
1817 if (config->IsReady()) {
1818 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id);
1819 if (carrier && !carrier->top_up_url().empty())
1820 dictionary->SetString(kTagCarrierUrl, carrier->top_up_url());
1823 base::ListValue* apn_list_value = new base::ListValue();
1824 const base::ListValue* apn_list;
1825 if (device_properties.GetListWithoutPathExpansion(
1826 shill::kCellularApnListProperty, &apn_list)) {
1827 for (base::ListValue::const_iterator iter = apn_list->begin();
1828 iter != apn_list->end(); ++iter) {
1829 const base::DictionaryValue* dict;
1830 if ((*iter)->GetAsDictionary(&dict)) {
1831 base::DictionaryValue* apn = new base::DictionaryValue;
1832 CreateDictionaryFromCellularApn(dict, apn);
1833 apn_list_value->Append(apn);
1837 SetValueDictionary(dictionary, kTagProviderApnList, apn_list_value,
1838 cellular_property_ui_data);
1839 if (CommandLine::ForCurrentProcess()->HasSwitch(
1840 chromeos::switches::kEnableCarrierSwitching)) {
1841 const base::ListValue* supported_carriers;
1842 if (device_properties.GetListWithoutPathExpansion(
1843 shill::kSupportedCarriersProperty, &supported_carriers)) {
1844 dictionary->Set(kTagCarriers, supported_carriers->DeepCopy());
1845 dictionary->SetInteger(kTagCurrentCarrierIndex,
1846 FindCurrentCarrierIndex(supported_carriers,
1847 device));
1848 } else {
1849 // In case of any error, set the current carrier tag to -1 indicating
1850 // to the JS code to fallback to a single carrier.
1851 dictionary->SetInteger(kTagCurrentCarrierIndex, -1);
1856 // Set Cellular Buttons Visibility
1857 dictionary->SetBoolean(
1858 kTagDisableConnectButton,
1859 cellular->activation_state() == shill::kActivationStateActivating ||
1860 cellular->IsConnectingState());
1862 // Don't show any account management related buttons if the activation
1863 // state is unknown or no payment portal URL is available.
1864 std::string support_url;
1865 if (cellular->activation_state() == shill::kActivationStateUnknown ||
1866 !dictionary->GetString(kTagSupportUrl, &support_url) ||
1867 support_url.empty()) {
1868 VLOG(2) << "No support URL is available. Don't display buttons.";
1869 return;
1872 if (cellular->activation_state() != shill::kActivationStateActivating &&
1873 cellular->activation_state() != shill::kActivationStateActivated) {
1874 dictionary->SetBoolean(kTagShowActivateButton, true);
1875 } else {
1876 bool may_show_portal_button = false;
1878 // If an online payment URL was provided by shill, then this means that the
1879 // "View Account" button should be shown for the current carrier.
1880 if (olp) {
1881 std::string url;
1882 olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url);
1883 may_show_portal_button = !url.empty();
1885 // If no online payment URL was provided by shill, fall back to
1886 // MobileConfig to determine if the "View Account" should be shown.
1887 if (!may_show_portal_button && MobileConfig::GetInstance()->IsReady()) {
1888 const MobileConfig::Carrier* carrier =
1889 MobileConfig::GetInstance()->GetCarrier(carrier_id);
1890 may_show_portal_button = carrier && carrier->show_portal_button();
1892 if (may_show_portal_button) {
1893 // The button should be shown for a LTE network even when the LTE network
1894 // is not connected, but CrOS is online. This is done to enable users to
1895 // update their plan even if they are out of credits.
1896 // The button should not be shown when the device's mdn is not set,
1897 // because the network's proper portal url cannot be generated without it
1898 const NetworkState* default_network =
1899 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
1900 const std::string& technology = cellular->network_technology();
1901 bool force_show_view_account_button =
1902 (technology == shill::kNetworkTechnologyLte ||
1903 technology == shill::kNetworkTechnologyLteAdvanced) &&
1904 default_network &&
1905 !mdn.empty();
1907 // The button will trigger ShowMorePlanInfoCallback() which will open
1908 // carrier specific portal.
1909 if (cellular->IsConnectedState() || force_show_view_account_button)
1910 dictionary->SetBoolean(kTagShowViewAccountButton, true);
1915 } // namespace
1917 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const {
1918 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow();
1921 void InternetOptionsHandler::NetworkCommandCallback(
1922 const base::ListValue* args) {
1923 std::string type;
1924 std::string service_path;
1925 std::string command;
1926 if (args->GetSize() != 3 ||
1927 !args->GetString(0, &type) ||
1928 !args->GetString(1, &service_path) ||
1929 !args->GetString(2, &command)) {
1930 NOTREACHED();
1931 return;
1934 // Process commands that do not require an existing network.
1935 if (command == kTagAddConnection) {
1936 if (CanAddNetworkType(type))
1937 AddConnection(type);
1938 } else if (command == kTagForget) {
1939 if (CanForgetNetworkType(type)) {
1940 NetworkHandler::Get()->network_configuration_handler()->
1941 RemoveConfiguration(
1942 service_path,
1943 base::Bind(&base::DoNothing),
1944 base::Bind(&ShillError, "NetworkCommand: " + command));
1946 } else if (command == kTagOptions) {
1947 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1948 service_path,
1949 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback,
1950 weak_factory_.GetWeakPtr()),
1951 base::Bind(&ShillError, "NetworkCommand: " + command));
1952 } else if (command == kTagConnect) {
1953 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow());
1954 } else if (command == kTagDisconnect) {
1955 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork(
1956 service_path,
1957 base::Bind(&base::DoNothing),
1958 base::Bind(&ShillError, "NetworkCommand: " + command));
1959 } else if (command == kTagConfigure) {
1960 NetworkConfigView::Show(service_path, GetNativeWindow());
1961 } else if (command == kTagActivate && type == shill::kTypeCellular) {
1962 ash::network_connect::ActivateCellular(service_path);
1963 // Activation may update network properties (e.g. ActivationState), so
1964 // request them here in case they change.
1965 UpdateConnectionData(service_path);
1966 } else {
1967 VLOG(1) << "Unknown command: " << command;
1968 NOTREACHED();
1972 void InternetOptionsHandler::AddConnection(const std::string& type) {
1973 if (type == shill::kTypeWifi)
1974 NetworkConfigView::ShowForType(shill::kTypeWifi, GetNativeWindow());
1975 else if (type == shill::kTypeVPN)
1976 NetworkConfigView::ShowForType(shill::kTypeVPN, GetNativeWindow());
1977 else if (type == shill::kTypeCellular)
1978 ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
1979 else
1980 NOTREACHED();
1983 base::ListValue* InternetOptionsHandler::GetWiredList() {
1984 base::ListValue* list = new base::ListValue();
1985 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
1986 FirstNetworkByType(NetworkTypePattern::Ethernet());
1987 if (!network)
1988 return list;
1989 list->Append(
1990 BuildNetworkDictionary(network,
1991 web_ui()->GetDeviceScaleFactor(),
1992 Profile::FromWebUI(web_ui())->GetPrefs()));
1993 return list;
1996 base::ListValue* InternetOptionsHandler::GetWirelessList() {
1997 base::ListValue* list = new base::ListValue();
1999 NetworkStateHandler::NetworkStateList networks;
2000 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
2001 NetworkTypePattern::Wireless(), &networks);
2002 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
2003 networks.begin(); iter != networks.end(); ++iter) {
2004 list->Append(
2005 BuildNetworkDictionary(*iter,
2006 web_ui()->GetDeviceScaleFactor(),
2007 Profile::FromWebUI(web_ui())->GetPrefs()));
2010 return list;
2013 base::ListValue* InternetOptionsHandler::GetVPNList() {
2014 base::ListValue* list = new base::ListValue();
2016 NetworkStateHandler::NetworkStateList networks;
2017 NetworkHandler::Get()->network_state_handler()->GetNetworkListByType(
2018 NetworkTypePattern::VPN(), &networks);
2019 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
2020 networks.begin(); iter != networks.end(); ++iter) {
2021 list->Append(
2022 BuildNetworkDictionary(*iter,
2023 web_ui()->GetDeviceScaleFactor(),
2024 Profile::FromWebUI(web_ui())->GetPrefs()));
2027 return list;
2030 base::ListValue* InternetOptionsHandler::GetRememberedList() {
2031 base::ListValue* list = new base::ListValue();
2033 NetworkStateHandler::FavoriteStateList favorites;
2034 NetworkHandler::Get()->network_state_handler()->GetFavoriteList(&favorites);
2035 for (NetworkStateHandler::FavoriteStateList::const_iterator iter =
2036 favorites.begin(); iter != favorites.end(); ++iter) {
2037 const FavoriteState* favorite = *iter;
2038 if (favorite->type() != shill::kTypeWifi &&
2039 favorite->type() != shill::kTypeVPN)
2040 continue;
2041 list->Append(
2042 BuildFavoriteDictionary(favorite,
2043 web_ui()->GetDeviceScaleFactor(),
2044 Profile::FromWebUI(web_ui())->GetPrefs()));
2047 return list;
2050 void InternetOptionsHandler::FillNetworkInfo(
2051 base::DictionaryValue* dictionary) {
2052 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
2053 dictionary->Set(kTagWiredList, GetWiredList());
2054 dictionary->Set(kTagWirelessList, GetWirelessList());
2055 dictionary->Set(kTagVpnList, GetVPNList());
2056 dictionary->Set(kTagRememberedList, GetRememberedList());
2058 dictionary->SetBoolean(
2059 kTagWifiAvailable,
2060 handler->IsTechnologyAvailable(NetworkTypePattern::WiFi()));
2061 dictionary->SetBoolean(
2062 kTagWifiEnabled,
2063 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()));
2065 dictionary->SetBoolean(
2066 kTagCellularAvailable,
2067 handler->IsTechnologyAvailable(NetworkTypePattern::Mobile()));
2068 dictionary->SetBoolean(
2069 kTagCellularEnabled,
2070 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()));
2071 const DeviceState* cellular =
2072 handler->GetDeviceStateByType(NetworkTypePattern::Mobile());
2073 dictionary->SetBoolean(
2074 kTagCellularSupportsScan,
2075 cellular && cellular->support_network_scan());
2077 dictionary->SetBoolean(
2078 kTagWimaxAvailable,
2079 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax()));
2080 dictionary->SetBoolean(
2081 kTagWimaxEnabled,
2082 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()));
2085 } // namespace options
2086 } // namespace chromeos