blob: 7cb132186f71bedbd65c0ba86feea86b9508cb86 [file] [log] [blame]
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001// Copyright (c) 2012 The Chromium Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5#include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
6
7#include <ctype.h>
8
9#include <map>
10#include <string>
11#include <vector>
12
13#include "ash/shell.h"
14#include "ash/shell_delegate.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010015#include "ash/system/chromeos/network/network_connect.h"
16#include "ash/system/chromeos/network/network_icon.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000017#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"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010024#include "base/strings/string16.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000025#include "base/strings/string_number_conversions.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010026#include "base/strings/stringprintf.h"
27#include "base/strings/utf_string_conversions.h"
Ben Murdocheb525c52013-07-10 11:40:50 +010028#include "base/time/time.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000029#include "base/values.h"
30#include "chrome/browser/browser_process.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010031#include "chrome/browser/chrome_notification_types.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000032#include "chrome/browser/chromeos/choose_mobile_network_dialog.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000033#include "chrome/browser/chromeos/cros/network_library.h"
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +010034#include "chrome/browser/chromeos/cros/network_property_ui_data.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000035#include "chrome/browser/chromeos/enrollment_dialog_view.h"
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010036#include "chrome/browser/chromeos/login/user.h"
37#include "chrome/browser/chromeos/login/user_manager.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000038#include "chrome/browser/chromeos/mobile_config.h"
39#include "chrome/browser/chromeos/options/network_config_view.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010040#include "chrome/browser/chromeos/options/network_connect.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000041#include "chrome/browser/chromeos/settings/cros_settings.h"
42#include "chrome/browser/chromeos/sim_dialog_delegate.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010043#include "chrome/browser/chromeos/ui_proxy_config_service.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000044#include "chrome/browser/profiles/profile_manager.h"
45#include "chrome/browser/ui/browser.h"
46#include "chrome/browser/ui/browser_finder.h"
47#include "chrome/browser/ui/browser_window.h"
48#include "chrome/browser/ui/host_desktop.h"
49#include "chrome/browser/ui/singleton_tabs.h"
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +010050#include "chrome/browser/ui/webui/options/chromeos/core_chromeos_options_handler.h"
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +010051#include "chromeos/chromeos_switches.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010052#include "chromeos/network/device_state.h"
53#include "chromeos/network/favorite_state.h"
Ben Murdocha3f7b4e2013-07-24 10:36:34 +010054#include "chromeos/network/managed_network_configuration_handler.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010055#include "chromeos/network/network_configuration_handler.h"
56#include "chromeos/network/network_connection_handler.h"
57#include "chromeos/network/network_device_handler.h"
58#include "chromeos/network/network_event_log.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000059#include "chromeos/network/network_ip_config.h"
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010060#include "chromeos/network/network_profile.h"
61#include "chromeos/network/network_profile_handler.h"
62#include "chromeos/network/network_state.h"
63#include "chromeos/network/network_state_handler.h"
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +010064#include "chromeos/network/network_ui_data.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000065#include "chromeos/network/network_util.h"
66#include "chromeos/network/onc/onc_constants.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000067#include "content/public/browser/notification_service.h"
68#include "content/public/browser/web_contents.h"
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +010069#include "content/public/browser/web_contents_view.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000070#include "content/public/browser/web_ui.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000071#include "grit/ash_resources.h"
72#include "grit/ash_strings.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000073#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/gfx/display.h"
82#include "ui/gfx/image/image_skia.h"
83#include "ui/gfx/screen.h"
84#include "ui/views/widget/widget.h"
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +000085#include "ui/webui/web_ui_util.h"
Torne (Richard Coles)58218062012-11-14 11:43:16 +000086
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010087namespace chromeos {
88namespace options {
89
Torne (Richard Coles)58218062012-11-14 11:43:16 +000090namespace {
91
92// Keys for the network description dictionary passed to the web ui. Make sure
93// to keep the strings in sync with what the JavaScript side uses.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +010094const char kNetworkInfoKeyActivationState[] = "activationState";
Torne (Richard Coles)58218062012-11-14 11:43:16 +000095const char kNetworkInfoKeyConnectable[] = "connectable";
96const char kNetworkInfoKeyConnected[] = "connected";
97const char kNetworkInfoKeyConnecting[] = "connecting";
98const char kNetworkInfoKeyIconURL[] = "iconURL";
Torne (Richard Coles)58218062012-11-14 11:43:16 +000099const char kNetworkInfoKeyNetworkName[] = "networkName";
100const char kNetworkInfoKeyNetworkStatus[] = "networkStatus";
101const char kNetworkInfoKeyNetworkType[] = "networkType";
102const char kNetworkInfoKeyRemembered[] = "remembered";
103const char kNetworkInfoKeyServicePath[] = "servicePath";
104const char kNetworkInfoKeyPolicyManaged[] = "policyManaged";
105
106// These are keys for getting IP information from the web ui.
107const char kIpConfigAddress[] = "address";
108const char kIpConfigPrefixLength[] = "prefixLength";
109const char kIpConfigNetmask[] = "netmask";
110const char kIpConfigGateway[] = "gateway";
111const char kIpConfigNameServers[] = "nameServers";
112const char kIpConfigAutoConfig[] = "ipAutoConfig";
113
114// These are types of name server selections from the web ui.
115const char kNameServerTypeAutomatic[] = "automatic";
116const char kNameServerTypeGoogle[] = "google";
117const char kNameServerTypeUser[] = "user";
118
119// These are dictionary names used to send data to the web ui.
120const char kDictionaryIpConfig[] = "ipconfig";
121const char kDictionaryStaticIp[] = "staticIP";
122const char kDictionarySavedIp[] = "savedIP";
123
124// Google public name servers (DNS).
125const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8";
126
127// Functions we call in JavaScript.
128const char kRefreshNetworkDataFunction[] =
129 "options.network.NetworkList.refreshNetworkData";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000130const char kSetDefaultNetworkIconsFunction[] =
131 "options.network.NetworkList.setDefaultNetworkIcons";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000132const char kShowDetailedInfoFunction[] =
133 "options.internet.DetailsInternetPage.showDetailedInfo";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000134const char kUpdateConnectionDataFunction[] =
135 "options.internet.DetailsInternetPage.updateConnectionData";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000136const char kUpdateCarrierFunction[] =
137 "options.internet.DetailsInternetPage.updateCarrier";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000138const char kUpdateSecurityTabFunction[] =
139 "options.internet.DetailsInternetPage.updateSecurityTab";
140
141// These are used to register message handlers with JavaScript.
142const char kBuyDataPlanMessage[] = "buyDataPlan";
143const char kChangePinMessage[] = "changePin";
144const char kDisableCellularMessage[] = "disableCellular";
145const char kDisableWifiMessage[] = "disableWifi";
146const char kDisableWimaxMessage[] = "disableWimax";
147const char kEnableCellularMessage[] = "enableCellular";
148const char kEnableWifiMessage[] = "enableWifi";
149const char kEnableWimaxMessage[] = "enableWimax";
150const char kNetworkCommandMessage[] = "networkCommand";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000151const char kRefreshNetworksMessage[] = "refreshNetworks";
152const char kSetApnMessage[] = "setApn";
153const char kSetAutoConnectMessage[] = "setAutoConnect";
154const char kSetCarrierMessage[] = "setCarrier";
155const char kSetIPConfigMessage[] = "setIPConfig";
156const char kSetPreferNetworkMessage[] = "setPreferNetwork";
157const char kSetServerHostname[] = "setServerHostname";
158const char kSetSimCardLockMessage[] = "setSimCardLock";
159const char kShowMorePlanInfoMessage[] = "showMorePlanInfo";
160
161// These are strings used to communicate with JavaScript.
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000162const char kTagActivate[] = "activate";
163const char kTagActivated[] = "activated";
164const char kTagActivationState[] = "activationState";
165const char kTagAddConnection[] = "add";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000166const char kTagApn[] = "apn";
167const char kTagAutoConnect[] = "autoConnect";
168const char kTagBssid[] = "bssid";
169const char kTagCarrierSelectFlag[] = "showCarrierSelect";
170const char kTagCarrierUrl[] = "carrierUrl";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000171const char kTagCellular[] = "cellular";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000172const char kTagCellularAvailable[] = "cellularAvailable";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000173const char kTagCellularEnabled[] = "cellularEnabled";
174const char kTagCellularSupportsScan[] = "cellularSupportsScan";
Ben Murdoch2385ea32013-08-06 11:01:04 +0100175const char kTagConfigure[] = "configure";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000176const char kTagConnect[] = "connect";
177const char kTagConnected[] = "connected";
178const char kTagConnecting[] = "connecting";
179const char kTagConnectionState[] = "connectionState";
180const char kTagControlledBy[] = "controlledBy";
181const char kTagDataRemaining[] = "dataRemaining";
182const char kTagDeviceConnected[] = "deviceConnected";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000183const char kTagDisableConnectButton[] = "disableConnectButton";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000184const char kTagDisconnect[] = "disconnect";
185const char kTagEncryption[] = "encryption";
186const char kTagErrorState[] = "errorState";
187const char kTagEsn[] = "esn";
188const char kTagFirmwareRevision[] = "firmwareRevision";
189const char kTagForget[] = "forget";
190const char kTagFrequency[] = "frequency";
191const char kTagGsm[] = "gsm";
192const char kTagHardwareAddress[] = "hardwareAddress";
193const char kTagHardwareRevision[] = "hardwareRevision";
194const char kTagIdentity[] = "identity";
Torne (Richard Coles)c2e0dbd2013-05-09 18:35:53 +0100195const char kTagIccid[] = "iccid";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000196const char kTagImei[] = "imei";
197const char kTagImsi[] = "imsi";
198const char kTagLanguage[] = "language";
199const char kTagLastGoodApn[] = "lastGoodApn";
200const char kTagLocalizedName[] = "localizedName";
201const char kTagManufacturer[] = "manufacturer";
202const char kTagMdn[] = "mdn";
203const char kTagMeid[] = "meid";
204const char kTagMin[] = "min";
205const char kTagModelId[] = "modelId";
206const char kTagName[] = "name";
207const char kTagNameServersGoogle[] = "nameServersGoogle";
208const char kTagNameServerType[] = "nameServerType";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000209const char kTagNetworkId[] = "networkId";
210const char kTagNetworkName[] = "networkName";
211const char kTagNetworkTechnology[] = "networkTechnology";
212const char kTagOperatorCode[] = "operatorCode";
213const char kTagOperatorName[] = "operatorName";
214const char kTagOptions[] = "options";
215const char kTagPassword[] = "password";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000216const char kTagPolicy[] = "policy";
217const char kTagPreferred[] = "preferred";
218const char kTagPrlVersion[] = "prlVersion";
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100219const char kTagProviderType[] = "providerType";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000220const char kTagProviderApnList[] = "providerApnList";
221const char kTagRecommended[] = "recommended";
222const char kTagRecommendedValue[] = "recommendedValue";
223const char kTagRemembered[] = "remembered";
224const char kTagRememberedList[] = "rememberedList";
225const char kTagRestrictedPool[] = "restrictedPool";
226const char kTagRoamingState[] = "roamingState";
227const char kTagServerHostname[] = "serverHostname";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000228const char kTagCarriers[] = "carriers";
229const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
230const char kTagServiceName[] = "serviceName";
231const char kTagServicePath[] = "servicePath";
232const char kTagShared[] = "shared";
233const char kTagShowActivateButton[] = "showActivateButton";
234const char kTagShowBuyButton[] = "showBuyButton";
235const char kTagShowPreferred[] = "showPreferred";
236const char kTagShowProxy[] = "showProxy";
237const char kTagShowStaticIPConfig[] = "showStaticIPConfig";
238const char kTagShowViewAccountButton[] = "showViewAccountButton";
239const char kTagSimCardLockEnabled[] = "simCardLockEnabled";
240const char kTagSsid[] = "ssid";
241const char kTagStrength[] = "strength";
242const char kTagSupportUrl[] = "supportUrl";
243const char kTagTrue[] = "true";
244const char kTagType[] = "type";
245const char kTagUsername[] = "username";
246const char kTagValue[] = "value";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000247const char kTagVpn[] = "vpn";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000248const char kTagVpnList[] = "vpnList";
249const char kTagWarning[] = "warning";
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000250const char kTagWifi[] = "wifi";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000251const char kTagWifiAvailable[] = "wifiAvailable";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000252const char kTagWifiEnabled[] = "wifiEnabled";
253const char kTagWimaxAvailable[] = "wimaxAvailable";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000254const char kTagWimaxEnabled[] = "wimaxEnabled";
255const char kTagWiredList[] = "wiredList";
256const char kTagWirelessList[] = "wirelessList";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000257
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100258const int kPreferredPriority = 1;
259
260void ShillError(const std::string& function,
261 const std::string& error_name,
262 scoped_ptr<base::DictionaryValue> error_data) {
263 NET_LOG_ERROR("Shill Error from InternetOptionsHandler: " + error_name,
264 function);
265}
266
267const NetworkState* GetNetworkState(const std::string& service_path) {
268 return NetworkHandler::Get()->network_state_handler()->
269 GetNetworkState(service_path);
270}
271
272void SetNetworkProperty(const std::string& service_path,
273 const std::string& property,
274 base::Value* value) {
275 NET_LOG_EVENT("SetNetworkProperty: " + property, service_path);
276 base::DictionaryValue properties;
Ben Murdoch558790d2013-07-30 15:19:42 +0100277 properties.SetWithoutPathExpansion(property, value);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100278 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
279 service_path, properties,
280 base::Bind(&base::DoNothing),
281 base::Bind(&ShillError, "SetNetworkProperty"));
282}
283
Ben Murdochca12bfa2013-07-23 11:17:05 +0100284const base::DictionaryValue* FindPolicyForActiveUser(
285 const NetworkState* network,
286 onc::ONCSource* onc_source) {
Ben Murdocha3f7b4e2013-07-24 10:36:34 +0100287 const User* user = UserManager::Get()->GetActiveUser();
288 std::string username_hash = user ? user->username_hash() : std::string();
289 return NetworkHandler::Get()->managed_network_configuration_handler()
290 ->FindPolicyByGUID(username_hash, network->guid(), onc_source);
Ben Murdochca12bfa2013-07-23 11:17:05 +0100291}
292
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100293std::string ActivationStateString(const std::string& activation_state) {
294 int id;
295 if (activation_state == flimflam::kActivationStateActivated)
296 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_ACTIVATED;
297 else if (activation_state == flimflam::kActivationStateActivating)
298 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_ACTIVATING;
299 else if (activation_state == flimflam::kActivationStateNotActivated)
300 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_NOT_ACTIVATED;
301 else if (activation_state == flimflam::kActivationStatePartiallyActivated)
302 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_PARTIALLY_ACTIVATED;
303 else
304 id = IDS_CHROMEOS_NETWORK_ACTIVATION_STATE_UNKNOWN;
305 return l10n_util::GetStringUTF8(id);
306}
307
308std::string RoamingStateString(const std::string& roaming_state) {
309 int id;
310 if (roaming_state == flimflam::kRoamingStateHome)
311 id = IDS_CHROMEOS_NETWORK_ROAMING_STATE_HOME;
312 else if (roaming_state == flimflam::kRoamingStateRoaming)
313 id = IDS_CHROMEOS_NETWORK_ROAMING_STATE_ROAMING;
314 else
315 id = IDS_CHROMEOS_NETWORK_ROAMING_STATE_UNKNOWN;
316 return l10n_util::GetStringUTF8(id);
317}
318
319std::string ConnectionStateString(const std::string& state) {
320 int id;
321 if (state == flimflam::kUnknownString)
322 id = IDS_CHROMEOS_NETWORK_STATE_UNKNOWN;
323 else if (state == flimflam::kStateIdle)
324 id = IDS_CHROMEOS_NETWORK_STATE_IDLE;
325 else if (state == flimflam::kStateCarrier)
326 id = IDS_CHROMEOS_NETWORK_STATE_CARRIER;
327 else if (state == flimflam::kStateAssociation)
328 id = IDS_CHROMEOS_NETWORK_STATE_ASSOCIATION;
329 else if (state == flimflam::kStateConfiguration)
330 id = IDS_CHROMEOS_NETWORK_STATE_CONFIGURATION;
331 else if (state == flimflam::kStateReady)
332 id = IDS_CHROMEOS_NETWORK_STATE_READY;
333 else if (state == flimflam::kStateDisconnect)
334 id = IDS_CHROMEOS_NETWORK_STATE_DISCONNECT;
335 else if (state == flimflam::kStateFailure)
336 id = IDS_CHROMEOS_NETWORK_STATE_FAILURE;
337 else if (state == flimflam::kStateActivationFailure)
338 id = IDS_CHROMEOS_NETWORK_STATE_ACTIVATION_FAILURE;
339 else if (state == flimflam::kStatePortal)
340 id = IDS_CHROMEOS_NETWORK_STATE_PORTAL;
341 else if (state == flimflam::kStateOnline)
342 id = IDS_CHROMEOS_NETWORK_STATE_ONLINE;
343 else
344 id = IDS_CHROMEOS_NETWORK_STATE_UNRECOGNIZED;
345 return l10n_util::GetStringUTF8(id);
346}
347
348std::string EncryptionString(const std::string& security,
349 const std::string& eap_method) {
350 if (security == flimflam::kSecurityNone)
351 return "";
352 if (security == flimflam::kSecurityWpa)
353 return "WPA";
354 if (security == flimflam::kSecurityWep)
355 return "WEP";
356 if (security == flimflam::kSecurityRsn)
357 return "RSN";
358 if (security == flimflam::kSecurityPsk)
359 return "PSK";
360 if (security == flimflam::kSecurity8021x) {
361 std::string result = "8021X";
362 if (eap_method == flimflam::kEapMethodPEAP)
363 result += "PEAP";
364 else if (eap_method == flimflam::kEapMethodTLS)
365 result += "TLS";
366 else if (eap_method == flimflam::kEapMethodTTLS)
367 result += "TTLS";
368 else if (eap_method == flimflam::kEapMethodLEAP)
369 result += "LEAP";
370 return result;
371 }
372 return "Unknown";
373}
374
375std::string ProviderTypeString(
376 const std::string& provider_type,
Ben Murdoch558790d2013-07-30 15:19:42 +0100377 const base::DictionaryValue& provider_properties) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100378 int id;
379 if (provider_type == flimflam::kProviderL2tpIpsec) {
380 std::string client_cert_id;
Ben Murdoch558790d2013-07-30 15:19:42 +0100381 provider_properties.GetStringWithoutPathExpansion(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100382 flimflam::kL2tpIpsecClientCertIdProperty, &client_cert_id);
383 if (client_cert_id.empty())
384 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_PSK;
385 else
386 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_L2TP_IPSEC_USER_CERT;
387 } else if (provider_type == flimflam::kProviderOpenVpn) {
388 id = IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_OPEN_VPN;
389 } else {
390 id = IDS_CHROMEOS_NETWORK_ERROR_UNKNOWN;
391 }
392 return l10n_util::GetStringUTF8(id);
393}
394
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000395// A helper class for building network information dictionaries to be sent to
396// the webui code.
397class NetworkInfoDictionary {
398 public:
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100399 // Sets properties based on |network| and sets an appropriate icon based
400 // on the network type and |icon_scale_factor|.
401 NetworkInfoDictionary(const NetworkState* network,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000402 ui::ScaleFactor icon_scale_factor);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100403 NetworkInfoDictionary(const FavoriteState* network,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000404 ui::ScaleFactor icon_scale_factor);
405
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000406 // Builds the DictionaryValue representation from the previously set
407 // parameters. Ownership of the returned pointer is transferred to the caller.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100408 base::DictionaryValue* BuildDictionary();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000409
410 private:
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100411 void SetIcon(const gfx::ImageSkia& icon,
412 ui::ScaleFactor icon_scale_factor) {
413 gfx::ImageSkiaRep image_rep = icon.GetRepresentation(icon_scale_factor);
414 icon_url_ = icon.isNull() ? "" : webui::GetBitmapDataUrl(
415 image_rep.sk_bitmap());
416 }
417
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000418 std::string service_path_;
419 std::string icon_url_;
420 std::string name_;
421 bool connecting_;
422 bool connected_;
423 bool connectable_;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100424 std::string connection_type_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000425 bool remembered_;
426 bool shared_;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100427 std::string activation_state_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000428 bool policy_managed_;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000429
430 DISALLOW_COPY_AND_ASSIGN(NetworkInfoDictionary);
431};
432
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100433NetworkInfoDictionary::NetworkInfoDictionary(const NetworkState* network,
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000434 ui::ScaleFactor icon_scale_factor)
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100435 : service_path_(network->path()),
436 name_(network->name()),
437 connecting_(network->IsConnectingState()),
438 connected_(network->IsConnectedState()),
439 connectable_(network->connectable()),
440 connection_type_(network->type()),
441 remembered_(false),
442 shared_(false),
443 activation_state_(network->activation_state()),
444 policy_managed_(network->IsManaged()) {
445 if (network->type() == flimflam::kTypeEthernet)
446 name_ = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
447 gfx::ImageSkia icon = ash::network_icon::GetImageForNetwork(
448 network, ash::network_icon::ICON_TYPE_LIST);
449 SetIcon(icon, icon_scale_factor);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000450}
451
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100452NetworkInfoDictionary::NetworkInfoDictionary(const FavoriteState* favorite,
453 ui::ScaleFactor icon_scale_factor)
454 : service_path_(favorite->path()),
455 name_(favorite->name()),
456 connecting_(false),
457 connected_(false),
458 connectable_(false),
459 connection_type_(favorite->type()),
460 remembered_(true),
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +0100461 shared_(!favorite->IsPrivate()),
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100462 policy_managed_(favorite->IsManaged()) {
463 if (favorite->type() == flimflam::kTypeEthernet)
464 name_ = l10n_util::GetStringUTF8(IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET);
465 gfx::ImageSkia icon = ash::network_icon::GetImageForDisconnectedNetwork(
466 ash::network_icon::ICON_TYPE_LIST, favorite->type());
467 SetIcon(icon, icon_scale_factor);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000468}
469
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100470base::DictionaryValue* NetworkInfoDictionary::BuildDictionary() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000471 std::string status;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000472 if (remembered_) {
473 if (shared_)
474 status = l10n_util::GetStringUTF8(IDS_OPTIONS_SETTINGS_SHARED_NETWORK);
475 } else {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100476 int id;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000477 if (connected_)
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100478 id = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTED;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000479 else if (connecting_)
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100480 id = IDS_STATUSBAR_NETWORK_DEVICE_CONNECTING;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000481 else if (!connectable_)
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100482 id = IDS_STATUSBAR_NETWORK_DEVICE_NOT_CONFIGURED;
483 else
484 id = IDS_STATUSBAR_NETWORK_DEVICE_DISCONNECTED;
485 std::string status = l10n_util::GetStringUTF8(id);
486 if (connection_type_ == flimflam::kTypeCellular &&
487 activation_state_ != flimflam::kActivationStateActivated) {
488 status.append(" / ");
489 status.append(ActivationStateString(activation_state_));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000490 }
491 }
492
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100493 scoped_ptr<base::DictionaryValue> network_info(new base::DictionaryValue());
494 network_info->SetString(kNetworkInfoKeyActivationState, activation_state_);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000495 network_info->SetBoolean(kNetworkInfoKeyConnectable, connectable_);
496 network_info->SetBoolean(kNetworkInfoKeyConnected, connected_);
497 network_info->SetBoolean(kNetworkInfoKeyConnecting, connecting_);
498 network_info->SetString(kNetworkInfoKeyIconURL, icon_url_);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000499 network_info->SetString(kNetworkInfoKeyNetworkName, name_);
500 network_info->SetString(kNetworkInfoKeyNetworkStatus, status);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100501 network_info->SetString(kNetworkInfoKeyNetworkType, connection_type_);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000502 network_info->SetBoolean(kNetworkInfoKeyRemembered, remembered_);
503 network_info->SetString(kNetworkInfoKeyServicePath, service_path_);
504 network_info->SetBoolean(kNetworkInfoKeyPolicyManaged, policy_managed_);
505 return network_info.release();
506}
507
508// Pulls IP information out of a shill service properties dictionary. If
509// |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it
510// fetches "SavedIP.*" properties. Caller must take ownership of returned
511// dictionary. If non-NULL, |ip_parameters_set| returns a count of the number
512// of IP routing parameters that get set.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100513base::DictionaryValue* BuildIPInfoDictionary(
514 const base::DictionaryValue& shill_properties,
515 bool static_ip,
516 int* routing_parameters_set) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000517 std::string address_key;
518 std::string prefix_len_key;
519 std::string gateway_key;
520 std::string name_servers_key;
521 if (static_ip) {
522 address_key = shill::kStaticIPAddressProperty;
523 prefix_len_key = shill::kStaticIPPrefixlenProperty;
524 gateway_key = shill::kStaticIPGatewayProperty;
525 name_servers_key = shill::kStaticIPNameServersProperty;
526 } else {
527 address_key = shill::kSavedIPAddressProperty;
528 prefix_len_key = shill::kSavedIPPrefixlenProperty;
529 gateway_key = shill::kSavedIPGatewayProperty;
530 name_servers_key = shill::kSavedIPNameServersProperty;
531 }
532
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100533 scoped_ptr<base::DictionaryValue> ip_info_dict(new base::DictionaryValue);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000534 std::string address;
535 int routing_parameters = 0;
536 if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) {
537 ip_info_dict->SetString(kIpConfigAddress, address);
538 VLOG(2) << "Found " << address_key << ": " << address;
539 routing_parameters++;
540 }
541 int prefix_len = -1;
542 if (shill_properties.GetIntegerWithoutPathExpansion(
543 prefix_len_key, &prefix_len)) {
544 ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100545 std::string netmask = network_util::PrefixLengthToNetmask(prefix_len);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000546 ip_info_dict->SetString(kIpConfigNetmask, netmask);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000547 VLOG(2) << "Found " << prefix_len_key << ": "
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000548 << prefix_len << " (" << netmask << ")";
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000549 routing_parameters++;
550 }
551 std::string gateway;
552 if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) {
553 ip_info_dict->SetString(kIpConfigGateway, gateway);
554 VLOG(2) << "Found " << gateway_key << ": " << gateway;
555 routing_parameters++;
556 }
557 if (routing_parameters_set)
558 *routing_parameters_set = routing_parameters;
559
560 std::string name_servers;
561 if (shill_properties.GetStringWithoutPathExpansion(
562 name_servers_key, &name_servers)) {
563 ip_info_dict->SetString(kIpConfigNameServers, name_servers);
564 VLOG(2) << "Found " << name_servers_key << ": " << name_servers;
565 }
566
567 return ip_info_dict.release();
568}
569
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100570static bool CanForgetNetworkType(const std::string& type) {
571 return type == flimflam::kTypeWifi ||
572 type == flimflam::kTypeWimax ||
573 type == flimflam::kTypeVPN;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000574}
575
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100576static bool CanAddNetworkType(const std::string& type) {
577 return type == flimflam::kTypeWifi ||
578 type == flimflam::kTypeVPN ||
579 type == flimflam::kTypeCellular;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000580}
581
582// Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and
583// store it under |key| in |settings|. Takes ownership of |value|.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100584void SetValueDictionary(base::DictionaryValue* settings,
585 const char* key,
586 base::Value* value,
587 const NetworkPropertyUIData& ui_data) {
588 base::DictionaryValue* dict = new base::DictionaryValue();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000589 // DictionaryValue::Set() takes ownership of |value|.
590 dict->Set(kTagValue, value);
591 const base::Value* recommended_value = ui_data.default_value();
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100592 if (ui_data.IsManaged())
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000593 dict->SetString(kTagControlledBy, kTagPolicy);
594 else if (recommended_value && recommended_value->Equals(value))
595 dict->SetString(kTagControlledBy, kTagRecommended);
596
597 if (recommended_value)
598 dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
599 settings->Set(key, dict);
600}
601
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100602std::string CopyStringFromDictionary(const base::DictionaryValue& source,
603 const std::string& src_key,
604 const std::string& dest_key,
605 base::DictionaryValue* dest) {
606 std::string string_value;
607 if (source.GetStringWithoutPathExpansion(src_key, &string_value))
608 dest->SetStringWithoutPathExpansion(dest_key, string_value);
609 return string_value;
610}
611
612void CopyIntegerFromDictionary(const base::DictionaryValue& source,
613 const std::string& src_key,
614 const std::string& dest_key,
615 bool as_string,
616 base::DictionaryValue* dest) {
617 int int_value;
618 if (!source.GetIntegerWithoutPathExpansion(src_key, &int_value))
619 return;
620 if (as_string) {
621 std::string str = base::StringPrintf("%d", int_value);
622 dest->SetStringWithoutPathExpansion(dest_key, str);
623 } else {
624 dest->SetIntegerWithoutPathExpansion(dest_key, int_value);
625 }
626}
627
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000628// Fills |dictionary| with the configuration details of |vpn|. |onc| is required
629// for augmenting the policy-managed information.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100630void PopulateVPNDetails(const NetworkState* vpn,
631 const base::DictionaryValue& shill_properties,
632 base::DictionaryValue* dictionary) {
Ben Murdoch558790d2013-07-30 15:19:42 +0100633 // Name and Remembered are set in PopulateConnectionDetails().
634 // Provider properties are stored in the "Provider" dictionary.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100635 const base::DictionaryValue* provider_properties = NULL;
Ben Murdoch558790d2013-07-30 15:19:42 +0100636 if (!shill_properties.GetDictionaryWithoutPathExpansion(
637 flimflam::kProviderProperty, &provider_properties)) {
638 LOG(ERROR) << "No provider properties for VPN: " << vpn->path();
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100639 return;
Ben Murdoch558790d2013-07-30 15:19:42 +0100640 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100641 std::string provider_type;
Ben Murdoch558790d2013-07-30 15:19:42 +0100642 provider_properties->GetStringWithoutPathExpansion(
643 flimflam::kTypeProperty, &provider_type);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100644 dictionary->SetString(kTagProviderType,
Ben Murdoch558790d2013-07-30 15:19:42 +0100645 ProviderTypeString(provider_type,
646 *provider_properties));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000647
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100648 std::string username;
Ben Murdoch558790d2013-07-30 15:19:42 +0100649 if (provider_type == flimflam::kProviderOpenVpn) {
650 provider_properties->GetStringWithoutPathExpansion(
651 flimflam::kOpenVPNUserProperty, &username);
652 } else {
653 provider_properties->GetStringWithoutPathExpansion(
654 flimflam::kL2tpIpsecUserProperty, &username);
655 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100656 dictionary->SetString(kTagUsername, username);
657
Ben Murdochca12bfa2013-07-23 11:17:05 +0100658 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
659 const base::DictionaryValue* onc = FindPolicyForActiveUser(vpn, &onc_source);
660
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100661 NetworkPropertyUIData hostname_ui_data;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000662 hostname_ui_data.ParseOncProperty(
Ben Murdochca12bfa2013-07-23 11:17:05 +0100663 onc_source,
664 onc,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100665 base::StringPrintf("%s.%s", onc::network_config::kVPN, onc::vpn::kHost));
666 std::string provider_host;
Ben Murdoch558790d2013-07-30 15:19:42 +0100667 provider_properties->GetStringWithoutPathExpansion(
668 flimflam::kHostProperty, &provider_host);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000669 SetValueDictionary(dictionary, kTagServerHostname,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100670 new base::StringValue(provider_host),
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000671 hostname_ui_data);
672}
673
674// Given a list of supported carrier's by the device, return the index of
675// the carrier the device is currently using.
676int FindCurrentCarrierIndex(const base::ListValue* carriers,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100677 const DeviceState* device) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000678 DCHECK(carriers);
679 DCHECK(device);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100680 bool gsm = (device->technology_family() == flimflam::kTechnologyFamilyGsm);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000681 int index = 0;
682 for (base::ListValue::const_iterator it = carriers->begin();
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100683 it != carriers->end(); ++it, ++index) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000684 std::string value;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100685 if (!(*it)->GetAsString(&value))
686 continue;
687 // For GSM devices the device name will be empty, so simply select
688 // the Generic UMTS carrier option if present.
689 if (gsm && (value == shill::kCarrierGenericUMTS))
690 return index;
691 // For other carriers, the service name will match the carrier name.
692 if (value == device->carrier())
693 return index;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000694 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000695 return -1;
696}
697
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100698void PopulateWifiDetails(const NetworkState* wifi,
699 const base::DictionaryValue& shill_properties,
700 base::DictionaryValue* dictionary);
701// TODO(stevenjb): Move implementation here.
702
703void PopulateWimaxDetails(const NetworkState* wimax,
704 const base::DictionaryValue& shill_properties,
705 base::DictionaryValue* dictionary);
706// TODO(stevenjb): Move implementation here.
707
Ben Murdoch558790d2013-07-30 15:19:42 +0100708void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
709 base::DictionaryValue* dictionary);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100710// TODO(stevenjb): Move implementation here.
711
712void PopulateCellularDetails(const NetworkState* cellular,
713 const base::DictionaryValue& shill_properties,
714 base::DictionaryValue* dictionary);
715// TODO(stevenjb): Move implementation here.
716
717void PopulateConnectionDetails(const NetworkState* network,
718 const base::DictionaryValue& shill_properties,
719 base::DictionaryValue* dictionary);
720// TODO(stevenjb): Move implementation here.
721
722// Helper methods for SetIPConfigProperties
723void AppendPropertyKeyIfPresent(const std::string& key,
724 const base::DictionaryValue& old_properties,
725 std::vector<std::string>* property_keys) {
726 if (old_properties.HasKey(key))
727 property_keys->push_back(key);
728}
729
730void AddStringPropertyIfChanged(const std::string& key,
731 const std::string& new_value,
732 const base::DictionaryValue& old_properties,
733 base::DictionaryValue* new_properties) {
734 std::string old_value;
735 if (!old_properties.GetStringWithoutPathExpansion(key, &old_value) ||
736 new_value != old_value) {
737 new_properties->SetStringWithoutPathExpansion(key, new_value);
738 }
739}
740
741void AddIntegerPropertyIfChanged(const std::string& key,
742 int new_value,
743 const base::DictionaryValue& old_properties,
744 base::DictionaryValue* new_properties) {
745 int old_value;
746 if (!old_properties.GetIntegerWithoutPathExpansion(key, &old_value) ||
747 new_value != old_value) {
748 new_properties->SetIntegerWithoutPathExpansion(key, new_value);
749 }
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +0100750}
751
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000752} // namespace
753
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000754InternetOptionsHandler::InternetOptionsHandler()
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +0100755 : weak_factory_(this) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000756 registrar_.Add(this, chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100757 content::NotificationService::AllSources());
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000758 registrar_.Add(this, chrome::NOTIFICATION_ENTER_PIN_ENDED,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100759 content::NotificationService::AllSources());
760 NetworkHandler::Get()->network_state_handler()->AddObserver(this, FROM_HERE);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000761}
762
763InternetOptionsHandler::~InternetOptionsHandler() {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100764 if (NetworkHandler::IsInitialized()) {
765 NetworkHandler::Get()->network_state_handler()->RemoveObserver(
766 this, FROM_HERE);
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000767 }
768}
769
770void InternetOptionsHandler::GetLocalizedValues(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100771 base::DictionaryValue* localized_strings) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000772 DCHECK(localized_strings);
773
774 static OptionsStringResource resources[] = {
775
776 // Main settings page.
777
778 { "ethernetTitle", IDS_STATUSBAR_NETWORK_DEVICE_ETHERNET },
779 { "wifiTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIFI_NETWORK },
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100780 { "wimaxTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_WIMAX_NETWORK },
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000781 { "cellularTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_CELLULAR_NETWORK },
782 { "vpnTitle", IDS_OPTIONS_SETTINGS_SECTION_TITLE_PRIVATE_NETWORK },
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000783 { "networkNotConnected", IDS_OPTIONS_SETTINGS_NETWORK_NOT_CONNECTED },
784 { "networkConnected", IDS_CHROMEOS_NETWORK_STATE_READY },
785 { "joinOtherNetwork", IDS_OPTIONS_SETTINGS_NETWORK_OTHER },
786 { "networkOffline", IDS_OPTIONS_SETTINGS_NETWORK_OFFLINE },
787 { "networkDisabled", IDS_OPTIONS_SETTINGS_NETWORK_DISABLED },
788 { "networkOnline", IDS_OPTIONS_SETTINGS_NETWORK_ONLINE },
789 { "networkOptions", IDS_OPTIONS_SETTINGS_NETWORK_OPTIONS },
790 { "turnOffWifi", IDS_OPTIONS_SETTINGS_NETWORK_DISABLE_WIFI },
Ben Murdoch9ab55632013-07-18 11:57:30 +0100791 { "turnOffWimax", IDS_OPTIONS_SETTINGS_NETWORK_DISABLE_WIMAX },
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000792 { "turnOffCellular", IDS_OPTIONS_SETTINGS_NETWORK_DISABLE_CELLULAR },
793 { "disconnectNetwork", IDS_OPTIONS_SETTINGS_DISCONNECT },
794 { "preferredNetworks", IDS_OPTIONS_SETTINGS_PREFERRED_NETWORKS_LABEL },
795 { "preferredNetworksPage", IDS_OPTIONS_SETTINGS_PREFERRED_NETWORKS_TITLE },
796 { "useSharedProxies", IDS_OPTIONS_SETTINGS_USE_SHARED_PROXIES },
797 { "addConnectionTitle",
798 IDS_OPTIONS_SETTINGS_SECTION_TITLE_ADD_CONNECTION },
799 { "addConnectionWifi", IDS_OPTIONS_SETTINGS_ADD_CONNECTION_WIFI },
800 { "addConnectionVPN", IDS_STATUSBAR_NETWORK_ADD_VPN },
801 { "otherCellularNetworks", IDS_OPTIONS_SETTINGS_OTHER_CELLULAR_NETWORKS },
802 { "enableDataRoaming", IDS_OPTIONS_SETTINGS_ENABLE_DATA_ROAMING },
803 { "disableDataRoaming", IDS_OPTIONS_SETTINGS_DISABLE_DATA_ROAMING },
804 { "dataRoamingDisableToggleTooltip",
805 IDS_OPTIONS_SETTINGS_TOGGLE_DATA_ROAMING_RESTRICTION },
806 { "activateNetwork", IDS_STATUSBAR_NETWORK_DEVICE_ACTIVATE },
807
808 // Internet details dialog.
809
810 { "changeProxyButton",
811 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CHANGE_PROXY_BUTTON },
812 { "managedNetwork", IDS_OPTIONS_SETTINGS_MANAGED_NETWORK },
813 { "wifiNetworkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION },
814 { "vpnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_VPN },
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000815 { "cellularConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_CONNECTION },
816 { "cellularDeviceTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_DEVICE },
817 { "networkTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_NETWORK },
818 { "securityTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_SECURITY },
819 { "proxyTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_PROXY },
820 { "connectionState", IDS_OPTIONS_SETTINGS_INTERNET_CONNECTION_STATE },
821 { "inetAddress", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_ADDRESS },
822 { "inetNetmask", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SUBNETMASK },
823 { "inetGateway", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_GATEWAY },
824 { "inetNameServers", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_DNSSERVER },
825 { "ipAutomaticConfiguration",
826 IDS_OPTIONS_SETTINGS_INTERNET_IP_AUTOMATIC_CONFIGURATION },
827 { "automaticNameServers",
828 IDS_OPTIONS_SETTINGS_INTERNET_AUTOMATIC_NAME_SERVERS },
829 { "userNameServer1", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_1 },
830 { "userNameServer2", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_2 },
831 { "userNameServer3", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_3 },
832 { "userNameServer4", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVER_4 },
833 { "googleNameServers", IDS_OPTIONS_SETTINGS_INTERNET_GOOGLE_NAME_SERVERS },
834 { "userNameServers", IDS_OPTIONS_SETTINGS_INTERNET_USER_NAME_SERVERS },
835 { "hardwareAddress",
836 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_HARDWARE_ADDRESS },
837 { "detailsInternetDismiss", IDS_CLOSE },
838 { "activateButton", IDS_OPTIONS_SETTINGS_ACTIVATE },
839 { "buyplanButton", IDS_OPTIONS_SETTINGS_BUY_PLAN },
840 { "connectButton", IDS_OPTIONS_SETTINGS_CONNECT },
Ben Murdoch2385ea32013-08-06 11:01:04 +0100841 { "configureButton", IDS_OPTIONS_SETTINGS_CONFIGURE },
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000842 { "disconnectButton", IDS_OPTIONS_SETTINGS_DISCONNECT },
843 { "viewAccountButton", IDS_STATUSBAR_NETWORK_VIEW_ACCOUNT },
844
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +0100845 { "wimaxConnTabLabel", IDS_OPTIONS_SETTINGS_INTERNET_TAB_WIMAX },
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000846
847 // Wifi Tab.
848
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000849 { "inetSsid", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_ID },
850 { "inetBssid", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_BSSID },
851 { "inetEncryption",
852 IDS_OPTIONS_SETTIGNS_INTERNET_OPTIONS_NETWORK_ENCRYPTION },
853 { "inetFrequency",
854 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_FREQUENCY },
855 { "inetFrequencyFormat",
856 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_FREQUENCY_MHZ },
857 { "inetSignalStrength",
858 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_STRENGTH },
859 { "inetSignalStrengthFormat",
860 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_STRENGTH_PERCENTAGE },
861 { "inetPassProtected",
862 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NET_PROTECTED },
863 { "inetNetworkShared",
864 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_NETWORK_SHARED },
865 { "inetPreferredNetwork",
866 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PREFER_NETWORK },
867 { "inetAutoConnectNetwork",
868 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_AUTO_CONNECT },
869 { "inetLogin", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_LOGIN },
870 { "inetShowPass", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SHOWPASSWORD },
871 { "inetPassPrompt", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_PASSWORD },
872 { "inetSsidPrompt", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_SSID },
873 { "inetStatus", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_STATUS_TITLE },
874 { "inetConnect", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_CONNECT_TITLE },
875
876 // VPN Tab.
877
878 { "inetServiceName",
879 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVICE_NAME },
880 { "inetServerHostname",
881 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_SERVER_HOSTNAME },
882 { "inetProviderType",
883 IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_PROVIDER_TYPE },
884 { "inetUsername", IDS_OPTIONS_SETTINGS_INTERNET_OPTIONS_VPN_USERNAME },
885
886 // Cellular Tab.
887
888 { "serviceName", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_SERVICE_NAME },
889 { "networkTechnology",
890 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_NETWORK_TECHNOLOGY },
891 { "operatorName", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR },
892 { "operatorCode", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_OPERATOR_CODE },
893 { "activationState",
894 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACTIVATION_STATE },
895 { "roamingState", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ROAMING_STATE },
896 { "restrictedPool",
897 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_RESTRICTED_POOL },
898 { "errorState", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ERROR_STATE },
899 { "manufacturer", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MANUFACTURER },
900 { "modelId", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_MODEL_ID },
901 { "firmwareRevision",
902 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_FIRMWARE_REVISION },
903 { "hardwareRevision",
904 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_HARDWARE_REVISION },
905 { "prlVersion", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_PRL_VERSION },
906 { "cellularApnLabel", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN },
907 { "cellularApnOther", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_OTHER },
908 { "cellularApnUsername",
909 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_USERNAME },
910 { "cellularApnPassword",
911 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_PASSWORD },
912 { "cellularApnUseDefault",
913 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_CLEAR },
914 { "cellularApnSet", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_APN_SET },
915 { "cellularApnCancel", IDS_CANCEL },
916
917 // Security Tab.
918
919 { "accessSecurityTabLink",
920 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_ACCESS_SECURITY_TAB },
921 { "lockSimCard", IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_LOCK_SIM_CARD },
922 { "changePinButton",
923 IDS_OPTIONS_SETTINGS_INTERNET_CELLULAR_CHANGE_PIN_BUTTON },
924 };
925
926 RegisterStrings(localized_strings, resources, arraysize(resources));
927
928 std::string owner;
929 chromeos::CrosSettings::Get()->GetString(chromeos::kDeviceOwner, &owner);
930 localized_strings->SetString("ownerUserId", UTF8ToUTF16(owner));
931
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100932 base::DictionaryValue* network_dictionary = new base::DictionaryValue;
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000933 FillNetworkInfo(network_dictionary);
934 localized_strings->Set("networkData", network_dictionary);
935}
936
937void InternetOptionsHandler::InitializePage() {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100938 base::DictionaryValue dictionary;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +0000939 dictionary.SetString(kTagCellular,
940 GetIconDataUrl(IDR_AURA_UBER_TRAY_NETWORK_BARS_DARK));
941 dictionary.SetString(kTagWifi,
942 GetIconDataUrl(IDR_AURA_UBER_TRAY_NETWORK_ARCS_DARK));
943 dictionary.SetString(kTagVpn,
944 GetIconDataUrl(IDR_AURA_UBER_TRAY_NETWORK_VPN));
945 web_ui()->CallJavascriptFunction(kSetDefaultNetworkIconsFunction,
946 dictionary);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +0100947 NetworkHandler::Get()->network_state_handler()->RequestScan();
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000948}
949
950void InternetOptionsHandler::RegisterMessages() {
951 // Setup handlers specific to this panel.
952 web_ui()->RegisterMessageCallback(kNetworkCommandMessage,
953 base::Bind(&InternetOptionsHandler::NetworkCommandCallback,
954 base::Unretained(this)));
955 web_ui()->RegisterMessageCallback(kRefreshNetworksMessage,
956 base::Bind(&InternetOptionsHandler::RefreshNetworksCallback,
957 base::Unretained(this)));
Torne (Richard Coles)58218062012-11-14 11:43:16 +0000958 web_ui()->RegisterMessageCallback(kSetPreferNetworkMessage,
959 base::Bind(&InternetOptionsHandler::SetPreferNetworkCallback,
960 base::Unretained(this)));
961 web_ui()->RegisterMessageCallback(kSetAutoConnectMessage,
962 base::Bind(&InternetOptionsHandler::SetAutoConnectCallback,
963 base::Unretained(this)));
964 web_ui()->RegisterMessageCallback(kSetIPConfigMessage,
965 base::Bind(&InternetOptionsHandler::SetIPConfigCallback,
966 base::Unretained(this)));
967 web_ui()->RegisterMessageCallback(kEnableWifiMessage,
968 base::Bind(&InternetOptionsHandler::EnableWifiCallback,
969 base::Unretained(this)));
970 web_ui()->RegisterMessageCallback(kDisableWifiMessage,
971 base::Bind(&InternetOptionsHandler::DisableWifiCallback,
972 base::Unretained(this)));
973 web_ui()->RegisterMessageCallback(kEnableCellularMessage,
974 base::Bind(&InternetOptionsHandler::EnableCellularCallback,
975 base::Unretained(this)));
976 web_ui()->RegisterMessageCallback(kDisableCellularMessage,
977 base::Bind(&InternetOptionsHandler::DisableCellularCallback,
978 base::Unretained(this)));
979 web_ui()->RegisterMessageCallback(kEnableWimaxMessage,
980 base::Bind(&InternetOptionsHandler::EnableWimaxCallback,
981 base::Unretained(this)));
982 web_ui()->RegisterMessageCallback(kDisableWimaxMessage,
983 base::Bind(&InternetOptionsHandler::DisableWimaxCallback,
984 base::Unretained(this)));
985 web_ui()->RegisterMessageCallback(kBuyDataPlanMessage,
986 base::Bind(&InternetOptionsHandler::BuyDataPlanCallback,
987 base::Unretained(this)));
988 web_ui()->RegisterMessageCallback(kShowMorePlanInfoMessage,
989 base::Bind(&InternetOptionsHandler::ShowMorePlanInfoCallback,
990 base::Unretained(this)));
991 web_ui()->RegisterMessageCallback(kSetApnMessage,
992 base::Bind(&InternetOptionsHandler::SetApnCallback,
993 base::Unretained(this)));
994 web_ui()->RegisterMessageCallback(kSetCarrierMessage,
995 base::Bind(&InternetOptionsHandler::SetCarrierCallback,
996 base::Unretained(this)));
997 web_ui()->RegisterMessageCallback(kSetSimCardLockMessage,
998 base::Bind(&InternetOptionsHandler::SetSimCardLockCallback,
999 base::Unretained(this)));
1000 web_ui()->RegisterMessageCallback(kChangePinMessage,
1001 base::Bind(&InternetOptionsHandler::ChangePinCallback,
1002 base::Unretained(this)));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001003 web_ui()->RegisterMessageCallback(kSetServerHostname,
1004 base::Bind(&InternetOptionsHandler::SetServerHostnameCallback,
1005 base::Unretained(this)));
1006}
1007
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001008void InternetOptionsHandler::EnableWifiCallback(const base::ListValue* args) {
1009 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1010 flimflam::kTypeWifi, true,
1011 base::Bind(&ShillError, "EnableWifiCallback"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001012}
1013
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001014void InternetOptionsHandler::DisableWifiCallback(const base::ListValue* args) {
1015 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1016 flimflam::kTypeWifi, false,
1017 base::Bind(&ShillError, "DisableWifiCallback"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001018}
1019
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001020void InternetOptionsHandler::EnableCellularCallback(
1021 const base::ListValue* args) {
1022 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
Ben Murdoch58e6fbe2013-07-26 10:20:38 +01001023 const DeviceState* device =
1024 handler->GetDeviceStateByType(flimflam::kTypeCellular);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001025 if (!device) {
1026 LOG(ERROR) << "Mobile device not found.";
1027 return;
1028 }
1029 if (!device->sim_lock_type().empty()) {
1030 SimDialogDelegate::ShowDialog(GetNativeWindow(),
1031 SimDialogDelegate::SIM_DIALOG_UNLOCK);
1032 return;
1033 }
Ben Murdoch58e6fbe2013-07-26 10:20:38 +01001034 if (!handler->IsTechnologyEnabled(flimflam::kTypeCellular)) {
1035 handler->SetTechnologyEnabled(
1036 flimflam::kTypeCellular, true,
1037 base::Bind(&ShillError, "EnableCellularCallback"));
1038 return;
1039 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001040 if (device->IsSimAbsent()) {
1041 MobileConfig* config = MobileConfig::GetInstance();
1042 if (config->IsReady()) {
1043 const MobileConfig::LocaleConfig* locale_config =
1044 config->GetLocaleConfig();
1045 if (locale_config) {
1046 std::string setup_url = locale_config->setup_url();
1047 if (!setup_url.empty()) {
1048 chrome::ShowSingletonTab(GetAppropriateBrowser(), GURL(setup_url));
1049 return;
1050 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001051 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001052 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001053 // TODO(nkostylev): Show generic error message. http://crosbug.com/15444
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001054 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001055 LOG(ERROR) << "EnableCellularCallback called for enabled mobile device";
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001056}
1057
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001058void InternetOptionsHandler::DisableCellularCallback(
1059 const base::ListValue* args) {
1060 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1061 NetworkStateHandler::kMatchTypeMobile, false,
1062 base::Bind(&ShillError, "DisableCellularCallback"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001063}
1064
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001065void InternetOptionsHandler::EnableWimaxCallback(const base::ListValue* args) {
1066 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1067 flimflam::kTypeWimax, true,
1068 base::Bind(&ShillError, "EnableWimaxCallback"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001069}
1070
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001071void InternetOptionsHandler::DisableWimaxCallback(const base::ListValue* args) {
1072 NetworkHandler::Get()->network_state_handler()->SetTechnologyEnabled(
1073 flimflam::kTypeWimax, false,
1074 base::Bind(&ShillError, "DisableWimaxCallback"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001075}
1076
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001077void InternetOptionsHandler::ShowMorePlanInfoCallback(
1078 const base::ListValue* args) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001079 if (!web_ui())
1080 return;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001081 std::string service_path;
1082 if (args->GetSize() != 1 || !args->GetString(0, &service_path)) {
1083 NOTREACHED();
1084 return;
1085 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001086 network_connect::ShowMobileSetup(service_path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001087}
1088
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001089void InternetOptionsHandler::BuyDataPlanCallback(const base::ListValue* args) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001090 if (!web_ui())
1091 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001092 std::string service_path;
1093 if (args->GetSize() != 1 || !args->GetString(0, &service_path)) {
1094 NOTREACHED();
1095 return;
1096 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001097 network_connect::ShowMobileSetup(service_path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001098}
1099
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001100void InternetOptionsHandler::SetApnCallback(const base::ListValue* args) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001101 std::string service_path;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001102 if (!args->GetString(0, &service_path)) {
1103 NOTREACHED();
1104 return;
1105 }
1106 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1107 service_path,
1108 base::Bind(&InternetOptionsHandler::SetApnProperties,
1109 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())),
1110 base::Bind(&ShillError, "SetApnCallback"));
1111}
1112
1113void InternetOptionsHandler::SetApnProperties(
1114 const base::ListValue* args,
1115 const std::string& service_path,
1116 const base::DictionaryValue& shill_properties) {
1117 std::string apn, username, password;
1118 if (!args->GetString(1, &apn) ||
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001119 !args->GetString(2, &username) ||
1120 !args->GetString(3, &password)) {
1121 NOTREACHED();
1122 return;
1123 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001124 NET_LOG_EVENT("SetApnCallback", service_path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001125
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001126 if (apn.empty()) {
1127 std::vector<std::string> properties_to_clear;
1128 properties_to_clear.push_back(flimflam::kCellularApnProperty);
1129 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
1130 service_path, properties_to_clear,
1131 base::Bind(&base::DoNothing),
1132 base::Bind(&ShillError, "ClearCellularApnProperties"));
1133 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001134 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001135
1136 const base::DictionaryValue* shill_apn_dict = NULL;
1137 std::string network_id;
1138 if (shill_properties.GetDictionaryWithoutPathExpansion(
1139 flimflam::kCellularApnProperty, &shill_apn_dict)) {
1140 shill_apn_dict->GetStringWithoutPathExpansion(
1141 flimflam::kApnNetworkIdProperty, &network_id);
1142 }
1143 base::DictionaryValue properties;
1144 base::DictionaryValue* apn_dict = new base::DictionaryValue;
1145 apn_dict->SetStringWithoutPathExpansion(flimflam::kApnProperty, apn);
1146 apn_dict->SetStringWithoutPathExpansion(flimflam::kApnNetworkIdProperty,
1147 network_id);
1148 apn_dict->SetStringWithoutPathExpansion(flimflam::kApnUsernameProperty,
1149 username);
1150 apn_dict->SetStringWithoutPathExpansion(flimflam::kApnPasswordProperty,
1151 password);
1152 properties.SetWithoutPathExpansion(flimflam::kCellularApnProperty, apn_dict);
1153 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
1154 service_path, properties,
1155 base::Bind(&base::DoNothing),
1156 base::Bind(&ShillError, "SetApnProperties"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001157}
1158
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001159void InternetOptionsHandler::CarrierStatusCallback() {
1160 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
1161 const DeviceState* device =
1162 handler->GetDeviceStateByType(flimflam::kTypeCellular);
1163 if (device && (device->carrier() == shill::kCarrierSprint)) {
1164 const NetworkState* network =
1165 handler->FirstNetworkByType(flimflam::kTypeCellular);
1166 if (network) {
1167 chromeos::network_connect::ActivateCellular(network->path());
1168 UpdateConnectionData(network->path());
1169 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001170 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001171 UpdateCarrier();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001172}
1173
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001174void InternetOptionsHandler::SetCarrierCallback(const base::ListValue* args) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001175 std::string service_path;
1176 std::string carrier;
1177 if (args->GetSize() != 2 ||
1178 !args->GetString(0, &service_path) ||
1179 !args->GetString(1, &carrier)) {
1180 NOTREACHED();
1181 return;
1182 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001183 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
1184 GetDeviceStateByType(flimflam::kTypeCellular);
1185 if (!device) {
1186 LOG(WARNING) << "SetCarrierCallback with no cellular device.";
1187 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001188 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001189 NetworkHandler::Get()->network_device_handler()->SetCarrier(
1190 device->path(),
1191 carrier,
1192 base::Bind(&InternetOptionsHandler::CarrierStatusCallback,
1193 weak_factory_.GetWeakPtr()),
1194 base::Bind(&ShillError, "SetCarrierCallback"));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001195}
1196
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001197void InternetOptionsHandler::SetSimCardLockCallback(
1198 const base::ListValue* args) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001199 bool require_pin_new_value;
1200 if (!args->GetBoolean(0, &require_pin_new_value)) {
1201 NOTREACHED();
1202 return;
1203 }
1204 // 1. Bring up SIM unlock dialog, pass new RequirePin setting in URL.
1205 // 2. Dialog will ask for current PIN in any case.
1206 // 3. If card is locked it will first call PIN unlock operation
1207 // 4. Then it will call Set RequirePin, passing the same PIN.
1208 // 5. We'll get notified by REQUIRE_PIN_SETTING_CHANGE_ENDED notification.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001209 SimDialogDelegate::SimDialogMode mode;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001210 if (require_pin_new_value)
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001211 mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_ON;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001212 else
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001213 mode = SimDialogDelegate::SIM_DIALOG_SET_LOCK_OFF;
1214 SimDialogDelegate::ShowDialog(GetNativeWindow(), mode);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001215}
1216
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001217void InternetOptionsHandler::ChangePinCallback(const base::ListValue* args) {
1218 SimDialogDelegate::ShowDialog(GetNativeWindow(),
1219 SimDialogDelegate::SIM_DIALOG_CHANGE_PIN);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001220}
1221
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001222void InternetOptionsHandler::RefreshNetworksCallback(
1223 const base::ListValue* args) {
1224 NetworkHandler::Get()->network_state_handler()->RequestScan();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001225}
1226
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001227std::string InternetOptionsHandler::GetIconDataUrl(int resource_id) const {
1228 gfx::ImageSkia* icon =
1229 ResourceBundle::GetSharedInstance().GetImageSkiaNamed(resource_id);
1230 gfx::ImageSkiaRep image_rep = icon->GetRepresentation(
1231 web_ui()->GetDeviceScaleFactor());
1232 return webui::GetBitmapDataUrl(image_rep.sk_bitmap());
1233}
1234
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001235void InternetOptionsHandler::RefreshNetworkData() {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001236 base::DictionaryValue dictionary;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001237 FillNetworkInfo(&dictionary);
1238 web_ui()->CallJavascriptFunction(
1239 kRefreshNetworkDataFunction, dictionary);
1240}
1241
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001242void InternetOptionsHandler::UpdateConnectionData(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001243 const std::string& service_path) {
1244 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1245 service_path,
1246 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback,
1247 weak_factory_.GetWeakPtr()),
1248 base::Bind(&ShillError, "UpdateConnectionData"));
1249}
1250
1251void InternetOptionsHandler::UpdateConnectionDataCallback(
1252 const std::string& service_path,
1253 const base::DictionaryValue& shill_properties) {
1254 const NetworkState* network = GetNetworkState(service_path);
1255 if (!network)
1256 return;
1257 base::DictionaryValue dictionary;
1258 PopulateConnectionDetails(network, shill_properties, &dictionary);
Torne (Richard Coles)868fa2f2013-06-11 10:57:03 +01001259 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, dictionary);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001260}
1261
1262void InternetOptionsHandler::UpdateCarrier() {
1263 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001264}
1265
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001266void InternetOptionsHandler::NetworkManagerChanged() {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001267 if (!web_ui())
1268 return;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001269 RefreshNetworkData();
1270}
1271
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001272void InternetOptionsHandler::NetworkListChanged() {
1273 if (!web_ui())
1274 return;
1275 RefreshNetworkData();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001276}
1277
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001278void InternetOptionsHandler::NetworkPropertiesUpdated(
1279 const NetworkState* network) {
1280 if (!web_ui())
1281 return;
1282 RefreshNetworkData();
1283 UpdateConnectionData(network->path());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001284}
1285
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001286void InternetOptionsHandler::Observe(
1287 int type,
1288 const content::NotificationSource& source,
1289 const content::NotificationDetails& details) {
1290 OptionsPageUIHandler::Observe(type, source, details);
1291 if (type == chrome::NOTIFICATION_REQUIRE_PIN_SETTING_CHANGE_ENDED) {
1292 base::FundamentalValue require_pin(*content::Details<bool>(details).ptr());
1293 web_ui()->CallJavascriptFunction(
1294 kUpdateSecurityTabFunction, require_pin);
1295 } else if (type == chrome::NOTIFICATION_ENTER_PIN_ENDED) {
1296 // We make an assumption (which is valid for now) that the SIM
1297 // unlock dialog is put up only when the user is trying to enable
1298 // mobile data.
1299 bool cancelled = *content::Details<bool>(details).ptr();
1300 if (cancelled)
1301 RefreshNetworkData();
1302 // The case in which the correct PIN was entered and the SIM is
1303 // now unlocked is handled in NetworkMenuButton.
1304 }
1305}
1306
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001307void InternetOptionsHandler::SetServerHostnameCallback(
1308 const base::ListValue* args) {
1309 std::string service_path, server_hostname;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001310 if (args->GetSize() < 2 ||
1311 !args->GetString(0, &service_path) ||
1312 !args->GetString(1, &server_hostname)) {
1313 NOTREACHED();
1314 return;
1315 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001316 SetNetworkProperty(service_path, flimflam::kProviderHostProperty,
1317 base::Value::CreateStringValue(server_hostname));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001318}
1319
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001320void InternetOptionsHandler::SetPreferNetworkCallback(
1321 const base::ListValue* args) {
1322 std::string service_path, prefer_network_str;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001323 if (args->GetSize() < 2 ||
1324 !args->GetString(0, &service_path) ||
1325 !args->GetString(1, &prefer_network_str)) {
1326 NOTREACHED();
1327 return;
1328 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001329 int priority = (prefer_network_str == kTagTrue) ? kPreferredPriority : 0;
1330 SetNetworkProperty(service_path, flimflam::kPriorityProperty,
1331 base::Value::CreateIntegerValue(priority));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001332}
1333
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001334void InternetOptionsHandler::SetAutoConnectCallback(
1335 const base::ListValue* args) {
1336 std::string service_path, auto_connect_str;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001337 if (args->GetSize() < 2 ||
1338 !args->GetString(0, &service_path) ||
1339 !args->GetString(1, &auto_connect_str)) {
1340 NOTREACHED();
1341 return;
1342 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001343 bool auto_connect = auto_connect_str == kTagTrue;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001344 SetNetworkProperty(service_path, flimflam::kAutoConnectProperty,
1345 base::Value::CreateBooleanValue(auto_connect));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001346}
1347
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001348void InternetOptionsHandler::SetIPConfigCallback(const base::ListValue* args) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001349 std::string service_path;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001350 if (!args->GetString(0, &service_path)) {
1351 NOTREACHED();
1352 return;
1353 }
1354 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
1355 service_path,
1356 base::Bind(&InternetOptionsHandler::SetIPConfigProperties,
1357 weak_factory_.GetWeakPtr(), base::Owned(args->DeepCopy())),
1358 base::Bind(&ShillError, "SetIPConfigCallback"));
1359}
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001360
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001361void InternetOptionsHandler::SetIPConfigProperties(
1362 const base::ListValue* args,
1363 const std::string& service_path,
1364 const base::DictionaryValue& shill_properties) {
1365 std::string address, netmask, gateway, name_server_type, name_servers;
1366 bool dhcp_for_ip;
1367 if (!args->GetBoolean(1, &dhcp_for_ip) ||
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001368 !args->GetString(2, &address) ||
1369 !args->GetString(3, &netmask) ||
1370 !args->GetString(4, &gateway) ||
1371 !args->GetString(5, &name_server_type) ||
1372 !args->GetString(6, &name_servers)) {
1373 NOTREACHED();
1374 return;
1375 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001376 NET_LOG_EVENT("SetIPConfigProperties", service_path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001377
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001378 std::vector<std::string> properties_to_clear;
1379 base::DictionaryValue properties_to_set;
1380
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001381 if (dhcp_for_ip) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001382 AppendPropertyKeyIfPresent(shill::kStaticIPAddressProperty,
1383 shill_properties, &properties_to_clear);
1384 AppendPropertyKeyIfPresent(shill::kStaticIPPrefixlenProperty,
1385 shill_properties, &properties_to_clear);
1386 AppendPropertyKeyIfPresent(shill::kStaticIPGatewayProperty,
1387 shill_properties, &properties_to_clear);
1388 } else {
1389 AddStringPropertyIfChanged(
1390 shill::kStaticIPAddressProperty,
1391 address, shill_properties, &properties_to_set);
1392 int prefixlen = network_util::NetmaskToPrefixLength(netmask);
1393 if (prefixlen > 0) {
1394 LOG(ERROR) << "Invalid prefix length for: " << service_path;
1395 prefixlen = 0;
1396 }
1397 AddIntegerPropertyIfChanged(
1398 shill::kStaticIPPrefixlenProperty,
1399 prefixlen, shill_properties, &properties_to_set);
1400 AddStringPropertyIfChanged(
1401 shill::kStaticIPGatewayProperty,
1402 gateway, shill_properties, &properties_to_set);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001403 }
1404
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001405 if (name_server_type == kNameServerTypeAutomatic) {
1406 AppendPropertyKeyIfPresent(shill::kStaticIPNameServersProperty,
1407 shill_properties, &properties_to_clear);
1408 } else {
1409 if (name_server_type == kNameServerTypeGoogle)
1410 name_servers = kGoogleNameServers;
1411 AddStringPropertyIfChanged(
1412 shill::kStaticIPNameServersProperty,
1413 name_servers, shill_properties, &properties_to_set);
1414 }
1415
1416 if (!properties_to_clear.empty()) {
1417 NetworkHandler::Get()->network_configuration_handler()->ClearProperties(
1418 service_path, properties_to_clear,
1419 base::Bind(&base::DoNothing),
1420 base::Bind(&ShillError, "ClearIPConfigProperties"));
1421 }
1422 if (!properties_to_set.empty()) {
1423 NetworkHandler::Get()->network_configuration_handler()->SetProperties(
1424 service_path, properties_to_set,
1425 base::Bind(&base::DoNothing),
1426 base::Bind(&ShillError, "SetIPConfigProperties"));
1427 }
1428 std::string device_path;
1429 shill_properties.GetStringWithoutPathExpansion(
1430 flimflam::kDeviceProperty, &device_path);
1431 if (!device_path.empty()) {
1432 // TODO(stevenjb): Enable this once 18873007 has landed.
1433 // NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs(
1434 // device_path);
1435 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001436}
1437
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001438void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001439 const std::string& service_path,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001440 const base::DictionaryValue& shill_properties) {
1441 const NetworkState* network = GetNetworkState(service_path);
1442 if (!network) {
1443 LOG(ERROR) << "Network properties not found: " << service_path;
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001444 return;
Ben Murdocheb525c52013-07-10 11:40:50 +01001445 }
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001446
Ben Murdochca12bfa2013-07-23 11:17:05 +01001447 onc::ONCSource onc_source = onc::ONC_SOURCE_NONE;
1448 const base::DictionaryValue* onc =
1449 FindPolicyForActiveUser(network, &onc_source);
1450 const NetworkPropertyUIData property_ui_data(onc_source);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001451
1452 base::DictionaryValue dictionary;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001453
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001454 // Device hardware address
1455 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
1456 GetDeviceState(network->device_path());
1457 if (device)
1458 dictionary.SetString(kTagHardwareAddress, device->mac_address());
1459
1460 // IP config
1461 scoped_ptr<base::DictionaryValue> ipconfig_dhcp(new base::DictionaryValue);
1462 ipconfig_dhcp->SetString(kIpConfigAddress, network->ip_address());
1463 ipconfig_dhcp->SetString(kIpConfigNetmask, network->GetNetmask());
1464 ipconfig_dhcp->SetString(kIpConfigGateway, network->gateway());
1465 std::string ipconfig_name_servers = network->GetDnsServersAsString();
1466 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers);
1467 SetValueDictionary(&dictionary,
1468 kDictionaryIpConfig,
1469 ipconfig_dhcp.release(),
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001470 property_ui_data);
1471
1472 std::string name_server_type = kNameServerTypeAutomatic;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001473 int automatic_ip_config = 0;
1474 scoped_ptr<base::DictionaryValue> static_ip_dict(
1475 BuildIPInfoDictionary(shill_properties, true, &automatic_ip_config));
1476 dictionary.SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0);
1477 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0)
1478 << "UI doesn't support automatic specification of individual "
1479 << "static IP parameters.";
1480 scoped_ptr<base::DictionaryValue> saved_ip_dict(
1481 BuildIPInfoDictionary(shill_properties, false, NULL));
1482 dictionary.Set(kDictionarySavedIp, saved_ip_dict.release());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001483
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001484 // Determine what kind of name server setting we have by comparing the
1485 // StaticIP and Google values with the ipconfig values.
1486 std::string static_ip_nameservers;
1487 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers);
1488 if (!static_ip_nameservers.empty() &&
1489 static_ip_nameservers == ipconfig_name_servers) {
1490 name_server_type = kNameServerTypeUser;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001491 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001492 if (ipconfig_name_servers == kGoogleNameServers) {
1493 name_server_type = kNameServerTypeGoogle;
1494 }
1495 SetValueDictionary(&dictionary,
1496 kDictionaryStaticIp,
1497 static_ip_dict.release(),
1498 property_ui_data);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001499
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001500 std::string type = network->type();
1501 dictionary.SetString(kTagType, type);
1502 dictionary.SetString(kTagServicePath, network->path());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001503 dictionary.SetString(kTagNameServerType, name_server_type);
1504 dictionary.SetString(kTagNameServersGoogle, kGoogleNameServers);
1505
1506 // Only show proxy for remembered networks.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001507 dictionary.SetBoolean(kTagShowProxy, !network->profile_path().empty());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001508
1509 // Enable static ip config for ethernet. For wifi, enable if flag is set.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001510 bool staticIPConfig = type == flimflam::kTypeEthernet ||
1511 (type == flimflam::kTypeWifi &&
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001512 CommandLine::ForCurrentProcess()->HasSwitch(
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +01001513 chromeos::switches::kEnableStaticIPConfig));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001514 dictionary.SetBoolean(kTagShowStaticIPConfig, staticIPConfig);
1515
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001516 dictionary.SetBoolean(kTagShowPreferred, !network->profile_path().empty());
1517 bool preferred = network->priority() > 0;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001518 SetValueDictionary(&dictionary, kTagPreferred,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001519 new base::FundamentalValue(preferred),
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001520 property_ui_data);
1521
Ben Murdochca12bfa2013-07-23 11:17:05 +01001522 NetworkPropertyUIData auto_connect_ui_data(onc_source);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001523 std::string onc_path_to_auto_connect;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001524 if (type == flimflam::kTypeWifi) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001525 onc_path_to_auto_connect = base::StringPrintf(
1526 "%s.%s",
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001527 onc::network_config::kWiFi,
1528 onc::wifi::kAutoConnect);
1529 } else if (type == flimflam::kTypeVPN) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001530 onc_path_to_auto_connect = base::StringPrintf(
1531 "%s.%s",
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001532 onc::network_config::kVPN,
1533 onc::vpn::kAutoConnect);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001534 }
1535 if (!onc_path_to_auto_connect.empty()) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001536 auto_connect_ui_data.ParseOncProperty(
Ben Murdochca12bfa2013-07-23 11:17:05 +01001537 onc_source, onc, onc_path_to_auto_connect);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001538 }
1539 SetValueDictionary(&dictionary, kTagAutoConnect,
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001540 new base::FundamentalValue(network->auto_connect()),
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001541 auto_connect_ui_data);
1542
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001543 PopulateConnectionDetails(network, shill_properties, &dictionary);
1544
1545 // Show details dialog
1546 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, dictionary);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001547}
1548
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001549namespace {
1550
1551void PopulateConnectionDetails(const NetworkState* network,
1552 const base::DictionaryValue& shill_properties,
1553 base::DictionaryValue* dictionary) {
1554 dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
1555 dictionary->SetString(kTagServiceName, network->name());
1556 dictionary->SetBoolean(kTagConnecting, network->IsConnectingState());
1557 dictionary->SetBoolean(kTagConnected, network->IsConnectedState());
1558 dictionary->SetString(kTagConnectionState,
1559 ConnectionStateString(network->connection_state()));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001560 dictionary->SetString(kTagNetworkName, network->name());
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001561 dictionary->SetString(kTagErrorState,
1562 ash::network_connect::ErrorString(network->error()));
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001563
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001564 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty());
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01001565 bool shared = !network->IsPrivate();
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001566 dictionary->SetBoolean(kTagShared, shared);
1567
1568 const std::string& type = network->type();
1569 const NetworkState* connected_network =
1570 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
1571 type);
1572
1573 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
1574
1575 if (type == flimflam::kTypeWifi)
1576 PopulateWifiDetails(network, shill_properties, dictionary);
1577 else if (type == flimflam::kTypeWimax)
1578 PopulateWimaxDetails(network, shill_properties, dictionary);
1579 else if (type == flimflam::kTypeCellular)
1580 PopulateCellularDetails(network, shill_properties, dictionary);
1581 else if (type == flimflam::kTypeVPN)
1582 PopulateVPNDetails(network, shill_properties, dictionary);
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001583}
1584
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001585void PopulateWifiDetails(const NetworkState* wifi,
1586 const base::DictionaryValue& shill_properties,
1587 base::DictionaryValue* dictionary) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001588 dictionary->SetString(kTagSsid, wifi->name());
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001589 dictionary->SetInteger(kTagStrength, wifi->signal_strength());
1590
1591 std::string security, eap_method;
1592 shill_properties.GetStringWithoutPathExpansion(
1593 flimflam::kSecurityProperty, &security);
1594 shill_properties.GetStringWithoutPathExpansion(
1595 flimflam::kEapMethodProperty, &eap_method);
1596 dictionary->SetString(kTagEncryption, EncryptionString(security, eap_method));
1597 CopyStringFromDictionary(shill_properties, flimflam::kWifiBSsid,
1598 kTagBssid, dictionary);
1599 CopyIntegerFromDictionary(shill_properties, flimflam::kWifiFrequency,
1600 kTagFrequency, false, dictionary);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001601}
1602
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001603void PopulateWimaxDetails(const NetworkState* wimax,
1604 const base::DictionaryValue& shill_properties,
1605 base::DictionaryValue* dictionary) {
1606 dictionary->SetInteger(kTagStrength, wimax->signal_strength());
1607 CopyStringFromDictionary(shill_properties, flimflam::kEapIdentityProperty,
1608 kTagIdentity, dictionary);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001609}
1610
Ben Murdoch558790d2013-07-30 15:19:42 +01001611void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn,
1612 base::DictionaryValue* dictionary) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001613 CopyStringFromDictionary(*apn, flimflam::kApnProperty,
1614 kTagApn, dictionary);
1615 CopyStringFromDictionary(*apn, flimflam::kApnNetworkIdProperty,
1616 kTagNetworkId, dictionary);
1617 CopyStringFromDictionary(*apn, flimflam::kApnUsernameProperty,
1618 kTagUsername, dictionary);
1619 CopyStringFromDictionary(*apn, flimflam::kApnPasswordProperty,
1620 kTagPassword, dictionary);
1621 CopyStringFromDictionary(*apn, flimflam::kApnNameProperty,
1622 kTagName, dictionary);
1623 CopyStringFromDictionary(*apn, flimflam::kApnLocalizedNameProperty,
1624 kTagLocalizedName, dictionary);
1625 CopyStringFromDictionary(*apn, flimflam::kApnLanguageProperty,
1626 kTagLanguage, dictionary);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001627}
1628
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001629void PopulateCellularDetails(const NetworkState* cellular,
1630 const base::DictionaryValue& shill_properties,
1631 base::DictionaryValue* dictionary) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001632 dictionary->SetBoolean(kTagCarrierSelectFlag,
1633 CommandLine::ForCurrentProcess()->HasSwitch(
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +01001634 chromeos::switches::kEnableCarrierSwitching));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001635 // Cellular network / connection settings.
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01001636 dictionary->SetString(kTagNetworkTechnology, cellular->network_technology());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001637 dictionary->SetString(kTagActivationState,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001638 ActivationStateString(cellular->activation_state()));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001639 dictionary->SetString(kTagRoamingState,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001640 RoamingStateString(cellular->roaming()));
1641 bool restricted = cellular->connection_state() == flimflam::kStatePortal;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001642 dictionary->SetString(kTagRestrictedPool,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001643 restricted ?
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001644 l10n_util::GetStringUTF8(
1645 IDS_CONFIRM_MESSAGEBOX_YES_BUTTON_LABEL) :
1646 l10n_util::GetStringUTF8(
1647 IDS_CONFIRM_MESSAGEBOX_NO_BUTTON_LABEL));
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01001648
1649 const base::DictionaryValue* serving_operator = NULL;
1650 if (shill_properties.GetDictionaryWithoutPathExpansion(
1651 flimflam::kServingOperatorProperty, &serving_operator)) {
1652 CopyStringFromDictionary(*serving_operator, flimflam::kOperatorNameKey,
1653 kTagOperatorName, dictionary);
1654 CopyStringFromDictionary(*serving_operator, flimflam::kOperatorCodeKey,
1655 kTagOperatorCode, dictionary);
1656 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001657
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001658 const base::DictionaryValue* olp = NULL;
Ben Murdoch558790d2013-07-30 15:19:42 +01001659 if (shill_properties.GetDictionaryWithoutPathExpansion(
1660 flimflam::kPaymentPortalProperty, &olp)) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001661 std::string url;
1662 olp->GetStringWithoutPathExpansion(flimflam::kPaymentPortalURL, &url);
1663 dictionary->SetString(kTagSupportUrl, url);
1664 }
1665
Ben Murdoch558790d2013-07-30 15:19:42 +01001666 base::DictionaryValue* apn = new base::DictionaryValue;
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001667 const base::DictionaryValue* source_apn = NULL;
Ben Murdoch558790d2013-07-30 15:19:42 +01001668 if (shill_properties.GetDictionaryWithoutPathExpansion(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001669 flimflam::kCellularApnProperty, &source_apn)) {
Ben Murdoch558790d2013-07-30 15:19:42 +01001670 CreateDictionaryFromCellularApn(source_apn, apn);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001671 }
Ben Murdoch558790d2013-07-30 15:19:42 +01001672 dictionary->Set(kTagApn, apn);
1673
1674 base::DictionaryValue* last_good_apn = new base::DictionaryValue;
1675 if (shill_properties.GetDictionaryWithoutPathExpansion(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001676 flimflam::kCellularLastGoodApnProperty, &source_apn)) {
Ben Murdoch558790d2013-07-30 15:19:42 +01001677 CreateDictionaryFromCellularApn(source_apn, last_good_apn);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001678 }
Ben Murdoch558790d2013-07-30 15:19:42 +01001679 dictionary->Set(kTagLastGoodApn, last_good_apn);
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001680
1681 // These default to empty and are only set if device != NULL.
1682 std::string carrier_id;
1683 std::string mdn;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001684
1685 // Device settings.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001686 const DeviceState* device = NetworkHandler::Get()->network_state_handler()->
1687 GetDeviceState(cellular->device_path());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001688 if (device) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001689 // TODO(stevenjb): Add NetworkDeviceHandler::GetProperties() and use that
1690 // to retrieve the complete dictionary of device properties, instead of
1691 // caching them (will be done for the new UI).
1692 const base::DictionaryValue& device_properties = device->properties();
1693 const NetworkPropertyUIData cellular_property_ui_data(
1694 cellular->onc_source());
1695 CopyStringFromDictionary(device_properties, flimflam::kManufacturerProperty,
1696 kTagManufacturer, dictionary);
1697 CopyStringFromDictionary(device_properties, flimflam::kModelIDProperty,
1698 kTagModelId, dictionary);
1699 CopyStringFromDictionary(device_properties,
1700 flimflam::kFirmwareRevisionProperty,
1701 kTagFirmwareRevision, dictionary);
1702 CopyStringFromDictionary(device_properties,
1703 flimflam::kHardwareRevisionProperty,
1704 kTagHardwareRevision, dictionary);
1705 CopyIntegerFromDictionary(device_properties, flimflam::kPRLVersionProperty,
1706 kTagPrlVersion, true, dictionary);
1707 CopyStringFromDictionary(device_properties, flimflam::kMeidProperty,
1708 kTagMeid, dictionary);
1709 CopyStringFromDictionary(device_properties, flimflam::kIccidProperty,
1710 kTagIccid, dictionary);
1711 CopyStringFromDictionary(device_properties, flimflam::kImeiProperty,
1712 kTagImei, dictionary);
1713 mdn = CopyStringFromDictionary(device_properties, flimflam::kMdnProperty,
1714 kTagMdn, dictionary);
1715 CopyStringFromDictionary(device_properties, flimflam::kImsiProperty,
1716 kTagImsi, dictionary);
1717 CopyStringFromDictionary(device_properties, flimflam::kEsnProperty,
1718 kTagEsn, dictionary);
1719 CopyStringFromDictionary(device_properties, flimflam::kMinProperty,
1720 kTagMin, dictionary);
1721 std::string family;
1722 device_properties.GetStringWithoutPathExpansion(
1723 flimflam::kTechnologyFamilyProperty, &family);
1724 dictionary->SetBoolean(kTagGsm, family == flimflam::kNetworkTechnologyGsm);
1725
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001726 SetValueDictionary(
1727 dictionary, kTagSimCardLockEnabled,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001728 new base::FundamentalValue(device->sim_lock_enabled()),
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001729 cellular_property_ui_data);
1730
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001731 carrier_id = device->home_provider_id();
1732
1733 MobileConfig* config = MobileConfig::GetInstance();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001734 if (config->IsReady()) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001735 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001736 if (carrier && !carrier->top_up_url().empty())
1737 dictionary->SetString(kTagCarrierUrl, carrier->top_up_url());
1738 }
1739
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001740 base::ListValue* apn_list_value = new base::ListValue();
1741 const base::ListValue* apn_list;
Ben Murdoch558790d2013-07-30 15:19:42 +01001742 if (device_properties.GetListWithoutPathExpansion(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001743 flimflam::kCellularApnListProperty, &apn_list)) {
1744 for (base::ListValue::const_iterator iter = apn_list->begin();
1745 iter != apn_list->end(); ++iter) {
1746 const base::DictionaryValue* dict;
Ben Murdoch558790d2013-07-30 15:19:42 +01001747 if ((*iter)->GetAsDictionary(&dict)) {
1748 base::DictionaryValue* apn = new base::DictionaryValue;
1749 CreateDictionaryFromCellularApn(dict, apn);
1750 apn_list_value->Append(apn);
1751 }
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001752 }
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001753 }
1754 SetValueDictionary(dictionary, kTagProviderApnList, apn_list_value,
1755 cellular_property_ui_data);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001756 if (CommandLine::ForCurrentProcess()->HasSwitch(
Torne (Richard Coles)b2df76e2013-05-13 16:52:09 +01001757 chromeos::switches::kEnableCarrierSwitching)) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001758 const base::ListValue* supported_carriers;
Ben Murdoch558790d2013-07-30 15:19:42 +01001759 if (device_properties.GetListWithoutPathExpansion(
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001760 shill::kSupportedCarriersProperty, &supported_carriers)) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001761 dictionary->Set(kTagCarriers, supported_carriers->DeepCopy());
1762 dictionary->SetInteger(kTagCurrentCarrierIndex,
1763 FindCurrentCarrierIndex(supported_carriers,
1764 device));
1765 } else {
1766 // In case of any error, set the current carrier tag to -1 indicating
1767 // to the JS code to fallback to a single carrier.
1768 dictionary->SetInteger(kTagCurrentCarrierIndex, -1);
1769 }
1770 }
1771 }
1772
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001773 // Set Cellular Buttons Visibility
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001774 dictionary->SetBoolean(
1775 kTagDisableConnectButton,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001776 cellular->activation_state() == flimflam::kActivationStateActivating ||
1777 cellular->IsConnectingState());
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001778
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001779 if (cellular->activation_state() != flimflam::kActivationStateActivating &&
1780 cellular->activation_state() != flimflam::kActivationStateActivated) {
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001781 dictionary->SetBoolean(kTagShowActivateButton, true);
1782 } else {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001783 const MobileConfig::Carrier* carrier =
1784 MobileConfig::GetInstance()->GetCarrier(carrier_id);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001785 if (carrier && carrier->show_portal_button()) {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001786 // The button should be shown for a LTE network even when the LTE network
1787 // is not connected, but CrOS is online. This is done to enable users to
1788 // update their plan even if they are out of credits.
1789 // The button should not be shown when the device's mdn is not set,
1790 // because the network's proper portal url cannot be generated without it
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001791 const NetworkState* default_network =
1792 NetworkHandler::Get()->network_state_handler()->DefaultNetwork();
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01001793 const std::string& technology = cellular->network_technology();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001794 bool force_show_view_account_button =
Torne (Richard Coles)a36e5922013-08-05 13:57:33 +01001795 (technology == flimflam::kNetworkTechnologyLte ||
1796 technology == flimflam::kNetworkTechnologyLteAdvanced) &&
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001797 default_network &&
1798 !mdn.empty();
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001799
1800 // The button will trigger ShowMorePlanInfoCallback() which will open
1801 // carrier specific portal.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001802 if (cellular->IsConnectedState() || force_show_view_account_button)
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001803 dictionary->SetBoolean(kTagShowViewAccountButton, true);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001804 }
1805 }
1806}
1807
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001808} // namespace
1809
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001810gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const {
Torne (Richard Coles)7d4cd472013-06-19 11:58:07 +01001811 return web_ui()->GetWebContents()->GetView()->GetTopLevelNativeWindow();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001812}
1813
1814Browser* InternetOptionsHandler::GetAppropriateBrowser() {
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001815 return chrome::FindOrCreateTabbedBrowser(
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001816 ProfileManager::GetDefaultProfileOrOffTheRecord(),
1817 chrome::HOST_DESKTOP_TYPE_ASH);
1818}
1819
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001820void InternetOptionsHandler::NetworkCommandCallback(
1821 const base::ListValue* args) {
1822 std::string type;
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001823 std::string service_path;
1824 std::string command;
1825 if (args->GetSize() != 3 ||
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001826 !args->GetString(0, &type) ||
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001827 !args->GetString(1, &service_path) ||
1828 !args->GetString(2, &command)) {
1829 NOTREACHED();
1830 return;
1831 }
1832
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001833 // Process commands that do not require an existing network.
1834 if (command == kTagAddConnection) {
1835 if (CanAddNetworkType(type))
1836 AddConnection(type);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001837 } else if (command == kTagForget) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001838 if (CanForgetNetworkType(type)) {
1839 NetworkHandler::Get()->network_configuration_handler()->
1840 RemoveConfiguration(
1841 service_path,
1842 base::Bind(&base::DoNothing),
1843 base::Bind(&ShillError, "NetworkCommand: " + command));
1844 }
1845 } else if (command == kTagOptions) {
1846 NetworkHandler::Get()->network_configuration_handler()->GetProperties(
Torne (Richard Coles)2a99a7e2013-03-28 15:31:22 +00001847 service_path,
1848 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001849 weak_factory_.GetWeakPtr()),
1850 base::Bind(&ShillError, "NetworkCommand: " + command));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001851 } else if (command == kTagConnect) {
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001852 network_connect::ConnectToNetwork(
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +01001853 service_path, GetNativeWindow());
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001854 } else if (command == kTagDisconnect) {
1855 NetworkHandler::Get()->network_connection_handler()->DisconnectNetwork(
1856 service_path,
1857 base::Bind(&base::DoNothing),
1858 base::Bind(&ShillError, "NetworkCommand: " + command));
Ben Murdoch2385ea32013-08-06 11:01:04 +01001859 } else if (command == kTagConfigure) {
1860 NetworkConfigView::ShowForPath(service_path, GetNativeWindow());
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001861 } else if (command == kTagActivate && type == flimflam::kTypeCellular) {
1862 network_connect::ActivateCellular(service_path);
Torne (Richard Coles)90dce4d2013-05-29 14:40:03 +01001863 // Activation may update network properties (e.g. ActivationState), so
1864 // request them here in case they change.
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001865 UpdateConnectionData(service_path);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001866 } else {
1867 VLOG(1) << "Unknown command: " << command;
1868 NOTREACHED();
1869 }
1870}
1871
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001872void InternetOptionsHandler::AddConnection(const std::string& type) {
1873 if (type == flimflam::kTypeWifi)
1874 NetworkConfigView::ShowForType(chromeos::TYPE_WIFI, GetNativeWindow());
1875 else if (type == flimflam::kTypeVPN)
1876 NetworkConfigView::ShowForType(chromeos::TYPE_VPN, GetNativeWindow());
1877 else if (type == flimflam::kTypeCellular)
1878 ChooseMobileNetworkDialog::ShowDialog(GetNativeWindow());
1879 else
1880 NOTREACHED();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001881}
1882
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001883base::ListValue* InternetOptionsHandler::GetWiredList() {
1884 base::ListValue* list = new base::ListValue();
1885 const NetworkState* network = NetworkHandler::Get()->network_state_handler()->
1886 FirstNetworkByType(flimflam::kTypeEthernet);
1887 if (!network)
1888 return list;
1889 NetworkInfoDictionary network_dict(network, web_ui()->GetDeviceScaleFactor());
1890 list->Append(network_dict.BuildDictionary());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001891 return list;
1892}
1893
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001894base::ListValue* InternetOptionsHandler::GetWirelessList() {
1895 base::ListValue* list = new base::ListValue();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001896
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001897 NetworkStateHandler::NetworkStateList networks;
1898 NetworkHandler::Get()->network_state_handler()->GetNetworkList(&networks);
1899 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1900 networks.begin(); iter != networks.end(); ++iter) {
1901 const NetworkState* network = *iter;
1902 if (network->type() != flimflam::kTypeWifi &&
1903 network->type() != flimflam::kTypeWimax &&
1904 network->type() != flimflam::kTypeCellular)
1905 continue;
1906 NetworkInfoDictionary network_dict(
1907 network, web_ui()->GetDeviceScaleFactor());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001908 list->Append(network_dict.BuildDictionary());
1909 }
1910
1911 return list;
1912}
1913
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001914base::ListValue* InternetOptionsHandler::GetVPNList() {
1915 base::ListValue* list = new base::ListValue();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001916
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001917 NetworkStateHandler::NetworkStateList networks;
1918 NetworkHandler::Get()->network_state_handler()->GetNetworkList(&networks);
1919 for (NetworkStateHandler::NetworkStateList::const_iterator iter =
1920 networks.begin(); iter != networks.end(); ++iter) {
1921 const NetworkState* network = *iter;
1922 if (network->type() != flimflam::kTypeVPN)
1923 continue;
1924 NetworkInfoDictionary network_dict(
1925 network, web_ui()->GetDeviceScaleFactor());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001926 list->Append(network_dict.BuildDictionary());
1927 }
1928
1929 return list;
1930}
1931
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001932base::ListValue* InternetOptionsHandler::GetRememberedList() {
1933 base::ListValue* list = new base::ListValue();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001934
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001935 NetworkStateHandler::FavoriteStateList favorites;
1936 NetworkHandler::Get()->network_state_handler()->GetFavoriteList(&favorites);
1937 for (NetworkStateHandler::FavoriteStateList::const_iterator iter =
1938 favorites.begin(); iter != favorites.end(); ++iter) {
1939 const FavoriteState* favorite = *iter;
1940 if (favorite->type() != flimflam::kTypeWifi &&
1941 favorite->type() != flimflam::kTypeVPN)
1942 continue;
1943 NetworkInfoDictionary network_dict(
1944 favorite, web_ui()->GetDeviceScaleFactor());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001945 list->Append(network_dict.BuildDictionary());
1946 }
1947
1948 return list;
1949}
1950
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001951void InternetOptionsHandler::FillNetworkInfo(
1952 base::DictionaryValue* dictionary) {
1953 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001954 dictionary->Set(kTagWiredList, GetWiredList());
1955 dictionary->Set(kTagWirelessList, GetWirelessList());
1956 dictionary->Set(kTagVpnList, GetVPNList());
1957 dictionary->Set(kTagRememberedList, GetRememberedList());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001958
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001959 dictionary->SetBoolean(kTagWifiAvailable,
1960 handler->IsTechnologyAvailable(flimflam::kTypeWifi));
1961 dictionary->SetBoolean(kTagWifiEnabled,
1962 handler->IsTechnologyEnabled(flimflam::kTypeWifi));
1963
1964 dictionary->SetBoolean(kTagCellularAvailable,
1965 handler->IsTechnologyAvailable(
1966 NetworkStateHandler::kMatchTypeMobile));
1967 dictionary->SetBoolean(kTagCellularEnabled,
1968 handler->IsTechnologyEnabled(
1969 NetworkStateHandler::kMatchTypeMobile));
1970 const DeviceState* cellular =
1971 handler->GetDeviceStateByType(NetworkStateHandler::kMatchTypeMobile);
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001972 dictionary->SetBoolean(
1973 kTagCellularSupportsScan,
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001974 cellular && cellular->support_network_scan());
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001975
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001976 dictionary->SetBoolean(kTagWimaxAvailable,
1977 handler->IsTechnologyAvailable(flimflam::kTypeWimax));
1978 dictionary->SetBoolean(kTagWimaxEnabled,
1979 handler->IsTechnologyEnabled(flimflam::kTypeWimax));
Torne (Richard Coles)58218062012-11-14 11:43:16 +00001980}
1981
1982} // namespace options
Ben Murdoch7dbb3d52013-07-17 14:55:54 +01001983} // namespace chromeos