Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(173)

Side by Side Diff: chrome/browser/ui/webui/options/chromeos/internet_options_handler.cc

Issue 509643003: Use GetManagedProperties in InternetOptionsHandler (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@issue_279351_internet_options_8a
Patch Set: Rebase, Clarify PrefixLengthToNetmask Created 6 years, 3 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch
« no previous file with comments | « chrome/browser/resources/options/chromeos/internet_detail.js ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved.
2 // Use of this source code is governed by a BSD-style license that can be 2 // Use of this source code is governed by a BSD-style license that can be
3 // found in the LICENSE file. 3 // found in the LICENSE file.
4 4
5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h" 5 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler.h"
6 6
7 #include <ctype.h> 7 #include <ctype.h>
8 8
9 #include <map> 9 #include <map>
10 #include <string> 10 #include <string>
(...skipping 13 matching lines...) Expand all
24 #include "chrome/browser/chromeos/options/network_property_ui_data.h" 24 #include "chrome/browser/chromeos/options/network_property_ui_data.h"
25 #include "chrome/browser/chromeos/settings/cros_settings.h" 25 #include "chrome/browser/chromeos/settings/cros_settings.h"
26 #include "chrome/browser/chromeos/sim_dialog_delegate.h" 26 #include "chrome/browser/chromeos/sim_dialog_delegate.h"
27 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h" 27 #include "chrome/browser/chromeos/ui/choose_mobile_network_dialog.h"
28 #include "chrome/browser/chromeos/ui/mobile_config_ui.h" 28 #include "chrome/browser/chromeos/ui/mobile_config_ui.h"
29 #include "chrome/browser/chromeos/ui_proxy_config_service.h" 29 #include "chrome/browser/chromeos/ui_proxy_config_service.h"
30 #include "chrome/browser/profiles/profile.h" 30 #include "chrome/browser/profiles/profile.h"
31 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h" 31 #include "chrome/browser/ui/webui/chromeos/mobile_setup_dialog.h"
32 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri ngs.h" 32 #include "chrome/browser/ui/webui/options/chromeos/internet_options_handler_stri ngs.h"
33 #include "chromeos/chromeos_switches.h" 33 #include "chromeos/chromeos_switches.h"
34 #include "chromeos/login/login_state.h"
34 #include "chromeos/network/device_state.h" 35 #include "chromeos/network/device_state.h"
35 #include "chromeos/network/managed_network_configuration_handler.h" 36 #include "chromeos/network/managed_network_configuration_handler.h"
36 #include "chromeos/network/network_configuration_handler.h" 37 #include "chromeos/network/network_configuration_handler.h"
37 #include "chromeos/network/network_connection_handler.h" 38 #include "chromeos/network/network_connection_handler.h"
38 #include "chromeos/network/network_device_handler.h" 39 #include "chromeos/network/network_device_handler.h"
39 #include "chromeos/network/network_event_log.h" 40 #include "chromeos/network/network_event_log.h"
40 #include "chromeos/network/network_ip_config.h" 41 #include "chromeos/network/network_ip_config.h"
41 #include "chromeos/network/network_profile.h" 42 #include "chromeos/network/network_profile.h"
42 #include "chromeos/network/network_profile_handler.h" 43 #include "chromeos/network/network_profile_handler.h"
43 #include "chromeos/network/network_state.h" 44 #include "chromeos/network/network_state.h"
(...skipping 18 matching lines...) Expand all
62 namespace options { 63 namespace options {
63 64
64 namespace { 65 namespace {
65 66
66 // Keys for the network description dictionary passed to the web ui. Make sure 67 // Keys for the network description dictionary passed to the web ui. Make sure
67 // to keep the strings in sync with what the JavaScript side uses. 68 // to keep the strings in sync with what the JavaScript side uses.
68 const char kNetworkInfoKeyIconURL[] = "iconURL"; 69 const char kNetworkInfoKeyIconURL[] = "iconURL";
69 const char kNetworkInfoKeyServicePath[] = "servicePath"; 70 const char kNetworkInfoKeyServicePath[] = "servicePath";
70 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged"; 71 const char kNetworkInfoKeyPolicyManaged[] = "policyManaged";
71 72
72 // These are keys for getting IP information from the web ui.
73 const char kIpConfigAddress[] = "address";
74 const char kIpConfigPrefixLength[] = "prefixLength";
75 const char kIpConfigNetmask[] = "netmask";
76 const char kIpConfigGateway[] = "gateway";
77 const char kIpConfigNameServers[] = "nameServers";
78 const char kIpConfigAutoConfig[] = "ipAutoConfig";
79 const char kIpConfigWebProxyAutoDiscoveryUrl[] = "webProxyAutoDiscoveryUrl";
80
81 // These are types of name server selections from the web ui. 73 // These are types of name server selections from the web ui.
82 const char kNameServerTypeAutomatic[] = "automatic"; 74 const char kNameServerTypeAutomatic[] = "automatic";
83 const char kNameServerTypeGoogle[] = "google"; 75 const char kNameServerTypeGoogle[] = "google";
84 const char kNameServerTypeUser[] = "user";
85
86 // These are dictionary names used to send data to the web ui.
87 const char kDictionaryIpConfig[] = "ipconfig";
88 const char kDictionaryStaticIp[] = "staticIP";
89 const char kDictionarySavedIp[] = "savedIP";
90 76
91 // Google public name servers (DNS). 77 // Google public name servers (DNS).
92 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8"; 78 const char kGoogleNameServers[] = "8.8.4.4,8.8.8.8";
93 79
94 // Functions we call in JavaScript. 80 // Functions we call in JavaScript.
95 const char kRefreshNetworkDataFunction[] = 81 const char kRefreshNetworkDataFunction[] =
96 "options.network.NetworkList.refreshNetworkData"; 82 "options.network.NetworkList.refreshNetworkData";
97 const char kSetDefaultNetworkIconsFunction[] = 83 const char kSetDefaultNetworkIconsFunction[] =
98 "options.network.NetworkList.setDefaultNetworkIcons"; 84 "options.network.NetworkList.setDefaultNetworkIcons";
99 const char kShowDetailedInfoFunction[] = 85 const char kShowDetailedInfoFunction[] =
(...skipping 26 matching lines...) Expand all
126 // These are strings used to communicate with JavaScript. 112 // These are strings used to communicate with JavaScript.
127 const char kTagActivate[] = "activate"; 113 const char kTagActivate[] = "activate";
128 const char kTagAddConnection[] = "add"; 114 const char kTagAddConnection[] = "add";
129 const char kTagCarrierSelectFlag[] = "showCarrierSelect"; 115 const char kTagCarrierSelectFlag[] = "showCarrierSelect";
130 const char kTagCarrierUrl[] = "carrierUrl"; 116 const char kTagCarrierUrl[] = "carrierUrl";
131 const char kTagCellularAvailable[] = "cellularAvailable"; 117 const char kTagCellularAvailable[] = "cellularAvailable";
132 const char kTagCellularEnabled[] = "cellularEnabled"; 118 const char kTagCellularEnabled[] = "cellularEnabled";
133 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; 119 const char kTagCellularSupportsScan[] = "cellularSupportsScan";
134 const char kTagConfigure[] = "configure"; 120 const char kTagConfigure[] = "configure";
135 const char kTagConnect[] = "connect"; 121 const char kTagConnect[] = "connect";
136 const char kTagControlledBy[] = "controlledBy";
137 const char kTagDeviceConnected[] = "deviceConnected"; 122 const char kTagDeviceConnected[] = "deviceConnected";
138 const char kTagDisconnect[] = "disconnect"; 123 const char kTagDisconnect[] = "disconnect";
139 const char kTagErrorMessage[] = "errorMessage"; 124 const char kTagErrorMessage[] = "errorMessage";
140 const char kTagForget[] = "forget"; 125 const char kTagForget[] = "forget";
141 const char kTagNameServersGoogle[] = "nameServersGoogle";
142 const char kTagNameServerType[] = "nameServerType";
143 const char kTagOptions[] = "options"; 126 const char kTagOptions[] = "options";
144 const char kTagPolicy[] = "policy";
145 const char kTagRecommended[] = "recommended";
146 const char kTagRecommendedValue[] = "recommendedValue";
147 const char kTagRemembered[] = "remembered"; 127 const char kTagRemembered[] = "remembered";
148 const char kTagRememberedList[] = "rememberedList"; 128 const char kTagRememberedList[] = "rememberedList";
149 const char kTagCarriers[] = "carriers"; 129 const char kTagCarriers[] = "carriers";
150 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex"; 130 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex";
151 const char kTagShared[] = "shared"; 131 const char kTagShared[] = "shared";
152 const char kTagShowActivateButton[] = "showActivateButton"; 132 const char kTagShowActivateButton[] = "showActivateButton";
153 const char kTagShowViewAccountButton[] = "showViewAccountButton"; 133 const char kTagShowViewAccountButton[] = "showViewAccountButton";
154 const char kTagTrue[] = "true"; 134 const char kTagTrue[] = "true";
155 const char kTagValue[] = "value";
156 const char kTagVpnList[] = "vpnList"; 135 const char kTagVpnList[] = "vpnList";
157 const char kTagWifiAvailable[] = "wifiAvailable"; 136 const char kTagWifiAvailable[] = "wifiAvailable";
158 const char kTagWifiEnabled[] = "wifiEnabled"; 137 const char kTagWifiEnabled[] = "wifiEnabled";
159 const char kTagWimaxAvailable[] = "wimaxAvailable"; 138 const char kTagWimaxAvailable[] = "wimaxAvailable";
160 const char kTagWimaxEnabled[] = "wimaxEnabled"; 139 const char kTagWimaxEnabled[] = "wimaxEnabled";
161 const char kTagWiredList[] = "wiredList"; 140 const char kTagWiredList[] = "wiredList";
162 const char kTagWirelessList[] = "wirelessList"; 141 const char kTagWirelessList[] = "wirelessList";
163 142
164 const int kPreferredPriority = 1; 143 const int kPreferredPriority = 1;
165 144
(...skipping 42 matching lines...) Expand 10 before | Expand all | Expand 10 after
208 187
209 std::string icon_url = ui::network_icon::GetImageUrlForNetwork( 188 std::string icon_url = ui::network_icon::GetImageUrlForNetwork(
210 network, ui::network_icon::ICON_TYPE_LIST, icon_scale_factor); 189 network, ui::network_icon::ICON_TYPE_LIST, icon_scale_factor);
211 190
212 network_info->SetString(kNetworkInfoKeyIconURL, icon_url); 191 network_info->SetString(kNetworkInfoKeyIconURL, icon_url);
213 network_info->SetString(kNetworkInfoKeyServicePath, network->path()); 192 network_info->SetString(kNetworkInfoKeyServicePath, network->path());
214 193
215 return network_info.release(); 194 return network_info.release();
216 } 195 }
217 196
218 // Pulls IP information out of a shill service properties dictionary. If
219 // |static_ip| is true, then it fetches "StaticIP.*" properties. If not, then it
220 // fetches "SavedIP.*" properties. Caller must take ownership of returned
221 // dictionary. If non-NULL, |ip_parameters_set| returns a count of the number
222 // of IP routing parameters that get set.
223 base::DictionaryValue* BuildIPInfoDictionary(
224 const base::DictionaryValue& shill_properties,
225 bool static_ip,
226 int* routing_parameters_set) {
227 std::string address_key;
228 std::string prefix_len_key;
229 std::string gateway_key;
230 std::string name_servers_key;
231 if (static_ip) {
232 address_key = shill::kStaticIPAddressProperty;
233 prefix_len_key = shill::kStaticIPPrefixlenProperty;
234 gateway_key = shill::kStaticIPGatewayProperty;
235 name_servers_key = shill::kStaticIPNameServersProperty;
236 } else {
237 address_key = shill::kSavedIPAddressProperty;
238 prefix_len_key = shill::kSavedIPPrefixlenProperty;
239 gateway_key = shill::kSavedIPGatewayProperty;
240 name_servers_key = shill::kSavedIPNameServersProperty;
241 }
242
243 scoped_ptr<base::DictionaryValue> ip_info_dict(new base::DictionaryValue);
244 std::string address;
245 int routing_parameters = 0;
246 if (shill_properties.GetStringWithoutPathExpansion(address_key, &address)) {
247 ip_info_dict->SetString(kIpConfigAddress, address);
248 VLOG(2) << "Found " << address_key << ": " << address;
249 routing_parameters++;
250 }
251 int prefix_len = -1;
252 if (shill_properties.GetIntegerWithoutPathExpansion(
253 prefix_len_key, &prefix_len)) {
254 ip_info_dict->SetInteger(kIpConfigPrefixLength, prefix_len);
255 std::string netmask = network_util::PrefixLengthToNetmask(prefix_len);
256 ip_info_dict->SetString(kIpConfigNetmask, netmask);
257 VLOG(2) << "Found " << prefix_len_key << ": "
258 << prefix_len << " (" << netmask << ")";
259 routing_parameters++;
260 }
261 std::string gateway;
262 if (shill_properties.GetStringWithoutPathExpansion(gateway_key, &gateway)) {
263 ip_info_dict->SetString(kIpConfigGateway, gateway);
264 VLOG(2) << "Found " << gateway_key << ": " << gateway;
265 routing_parameters++;
266 }
267 if (routing_parameters_set)
268 *routing_parameters_set = routing_parameters;
269
270 std::string name_servers;
271 if (shill_properties.GetStringWithoutPathExpansion(
272 name_servers_key, &name_servers)) {
273 ip_info_dict->SetString(kIpConfigNameServers, name_servers);
274 VLOG(2) << "Found " << name_servers_key << ": " << name_servers;
275 }
276
277 return ip_info_dict.release();
278 }
279
280 // Decorate pref value as CoreOptionsHandler::CreateValueForPref() does and
281 // store it under |key| in |settings|. Takes ownership of |value|.
282 void SetValueDictionary(const char* key,
283 base::Value* value,
284 const NetworkPropertyUIData& ui_data,
285 base::DictionaryValue* settings) {
286 base::DictionaryValue* dict = new base::DictionaryValue();
287 // DictionaryValue::Set() takes ownership of |value|.
288 dict->Set(kTagValue, value);
289 settings->Set(key, dict);
290
291 const base::Value* recommended_value = ui_data.default_value();
292 if (ui_data.IsManaged())
293 dict->SetString(kTagControlledBy, kTagPolicy);
294 else if (recommended_value && recommended_value->Equals(value))
295 dict->SetString(kTagControlledBy, kTagRecommended);
296
297 if (recommended_value)
298 dict->Set(kTagRecommendedValue, recommended_value->DeepCopy());
299 }
300
301 const char* GetOncPolicyString(::onc::ONCSource onc_source) {
302 if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
303 return ::onc::kAugmentationDevicePolicy;
304 return ::onc::kAugmentationUserPolicy;
305 }
306
307 const char* GetOncEditableString(::onc::ONCSource onc_source) {
308 if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
309 return ::onc::kAugmentationDeviceEditable;
310 return ::onc::kAugmentationUserEditable;
311 }
312
313 const char* GetOncSettingString(::onc::ONCSource onc_source) {
314 if (onc_source == ::onc::ONC_SOURCE_DEVICE_POLICY)
315 return ::onc::kAugmentationSharedSetting;
316 return ::onc::kAugmentationUserSetting;
317 }
318
319 // Creates a GetManagedProperties style dictionary and adds it to |settings|.
320 // |default_value| represents either the recommended value if |recommended|
321 // is true, or the enforced value if |recommended| is false. |settings_dict_key|
322 // is expected to be an ONC key with no '.' in it.
323 // Note(stevenjb): This is bridge code until we use GetManagedProperties to
324 // retrieve Shill properties.
325 void SetManagedValueDictionaryEx(const char* settings_dict_key,
326 const base::Value& value,
327 ::onc::ONCSource onc_source,
328 bool recommended,
329 const base::Value* default_value,
330 base::DictionaryValue* settings_dict) {
331 base::DictionaryValue* dict = new base::DictionaryValue();
332 settings_dict->SetWithoutPathExpansion(settings_dict_key, dict);
333
334 dict->Set(::onc::kAugmentationActiveSetting, value.DeepCopy());
335
336 if (onc_source == ::onc::ONC_SOURCE_NONE)
337 return;
338
339 if (recommended) {
340 // If an ONC property is 'Recommended' it can be edited by the user.
341 std::string editable = GetOncEditableString(onc_source);
342 dict->Set(editable, new base::FundamentalValue(true));
343 }
344 if (default_value) {
345 std::string policy_source = GetOncPolicyString(onc_source);
346 dict->Set(policy_source, default_value->DeepCopy());
347 if (recommended && !value.Equals(default_value)) {
348 std::string setting_source = GetOncSettingString(onc_source);
349 dict->Set(setting_source, value.DeepCopy());
350 dict->SetString(::onc::kAugmentationEffectiveSetting, setting_source);
351 } else {
352 dict->SetString(::onc::kAugmentationEffectiveSetting, policy_source);
353 }
354 }
355 }
356
357 // Wrapper for SetManagedValueDictionaryEx that does the policy lookup.
358 // Note: We have to pass |onc_key| separately from |settings_dict_key| since
359 // we might be populating a sub-dictionary in which case |onc_key| will be the
360 // complete path (e.g. 'VPN.Host') and |settings_dict_key| is the dictionary key
361 // (e.g. 'Host').
362 void SetManagedValueDictionary(const std::string& guid,
363 const char* settings_dict_key,
364 const base::Value& value,
365 const std::string& onc_key,
366 base::DictionaryValue* settings_dict) {
367 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
368 const base::DictionaryValue* onc =
369 onc::FindPolicyForActiveUser(guid, &onc_source);
370 DCHECK_EQ(onc == NULL, onc_source == ::onc::ONC_SOURCE_NONE);
371 const base::Value* default_value = NULL;
372 bool recommended = false;
373 if (onc) {
374 onc->Get(onc_key, &default_value);
375 recommended = onc::IsRecommendedValue(onc, onc_key);
376 }
377 SetManagedValueDictionaryEx(settings_dict_key,
378 value,
379 onc_source,
380 recommended,
381 default_value,
382 settings_dict);
383 }
384
385 // Fills |dictionary| with the configuration details of |vpn|. |onc| is required
386 // for augmenting the policy-managed information.
387 void PopulateVPNDetails(const NetworkState* vpn,
388 const base::DictionaryValue& shill_properties,
389 base::DictionaryValue* dictionary) {
390 // Name and Remembered are set in PopulateConnectionDetails().
391 // Provider properties are stored in the "Provider" dictionary.
392 const base::DictionaryValue* shill_provider_properties = NULL;
393 if (!shill_properties.GetDictionaryWithoutPathExpansion(
394 shill::kProviderProperty, &shill_provider_properties)) {
395 LOG(ERROR) << "No provider properties for VPN: " << vpn->path();
396 return;
397 }
398 base::DictionaryValue* vpn_dictionary;
399 if (!dictionary->GetDictionary(
400 ::onc::network_config::kVPN, &vpn_dictionary)) {
401 vpn_dictionary = new base::DictionaryValue;
402 dictionary->Set(::onc::network_config::kVPN, vpn_dictionary);
403 }
404
405 std::string shill_provider_type;
406 if (!shill_provider_properties->GetStringWithoutPathExpansion(
407 shill::kTypeProperty, &shill_provider_type)) {
408 LOG(ERROR) << "Shill VPN has no Provider.Type: " << vpn->path();
409 return;
410 }
411 std::string onc_provider_type;
412 onc::TranslateStringToONC(
413 onc::kVPNTypeTable, shill_provider_type, &onc_provider_type);
414 vpn_dictionary->SetString(::onc::vpn::kType, onc_provider_type);
415
416 std::string provider_type_key;
417 std::string username;
418 if (shill_provider_type == shill::kProviderOpenVpn) {
419 provider_type_key = ::onc::vpn::kOpenVPN;
420 shill_provider_properties->GetStringWithoutPathExpansion(
421 shill::kOpenVPNUserProperty, &username);
422 } else {
423 provider_type_key = ::onc::vpn::kL2TP;
424 shill_provider_properties->GetStringWithoutPathExpansion(
425 shill::kL2tpIpsecUserProperty, &username);
426 }
427 base::DictionaryValue* provider_type_dictionary = new base::DictionaryValue;
428 vpn_dictionary->Set(provider_type_key, provider_type_dictionary);
429 provider_type_dictionary->SetString(::onc::vpn::kUsername, username);
430
431 std::string provider_host;
432 shill_provider_properties->GetStringWithoutPathExpansion(
433 shill::kHostProperty, &provider_host);
434 SetManagedValueDictionary(
435 vpn->guid(),
436 ::onc::vpn::kHost,
437 base::StringValue(provider_host),
438 ::onc::network_config::VpnProperty(::onc::vpn::kHost),
439 vpn_dictionary);
440 }
441
442 // Given a list of supported carrier's by the device, return the index of 197 // Given a list of supported carrier's by the device, return the index of
443 // the carrier the device is currently using. 198 // the carrier the device is currently using.
444 int FindCurrentCarrierIndex(const base::ListValue* carriers, 199 int FindCurrentCarrierIndex(const base::ListValue* carriers,
445 const DeviceState* device) { 200 const DeviceState* device) {
446 DCHECK(carriers); 201 DCHECK(carriers);
447 DCHECK(device); 202 DCHECK(device);
448 bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm); 203 bool gsm = (device->technology_family() == shill::kTechnologyFamilyGsm);
449 int index = 0; 204 int index = 0;
450 for (base::ListValue::const_iterator it = carriers->begin(); 205 for (base::ListValue::const_iterator it = carriers->begin();
451 it != carriers->end(); ++it, ++index) { 206 it != carriers->end(); ++it, ++index) {
(...skipping 92 matching lines...) Expand 10 before | Expand all | Expand 10 after
544 // The button will trigger ShowMorePlanInfoCallback() which will open 299 // The button will trigger ShowMorePlanInfoCallback() which will open
545 // carrier specific portal. 300 // carrier specific portal.
546 if (cellular->IsConnectedState() || force_show_view_account_button) 301 if (cellular->IsConnectedState() || force_show_view_account_button)
547 dictionary->SetBoolean(kTagShowViewAccountButton, true); 302 dictionary->SetBoolean(kTagShowViewAccountButton, true);
548 } 303 }
549 } 304 }
550 } 305 }
551 306
552 scoped_ptr<base::DictionaryValue> PopulateConnectionDetails( 307 scoped_ptr<base::DictionaryValue> PopulateConnectionDetails(
553 const NetworkState* network, 308 const NetworkState* network,
554 const base::DictionaryValue& shill_properties) { 309 const base::DictionaryValue& onc_properties) {
555 // TODO(stevenjb): Once we eliminate all references to Shill properties, 310 scoped_ptr<base::DictionaryValue> dictionary(onc_properties.DeepCopy());
556 // we can switch to using managed_network_configuration_handler which
557 // includes Device properties for Cellular (and skip the call to
558 // onc::TranslateShillServiceToONCPart). For now we copy them over here.
559 scoped_ptr<base::DictionaryValue> shill_properties_with_device(
560 shill_properties.DeepCopy());
561 const DeviceState* device =
562 NetworkHandler::Get()->network_state_handler()->GetDeviceState(
563 network->device_path());
564 if (device) {
565 shill_properties_with_device->SetWithoutPathExpansion(
566 shill::kDeviceProperty, device->properties().DeepCopy());
567 // Get the hardware MAC address from the DeviceState.
568 // (Note: this is done in ManagedNetworkConfigurationHandler but not
569 // in NetworkConfigurationHandler).
570 if (!device->mac_address().empty()) {
571 shill_properties_with_device->SetStringWithoutPathExpansion(
572 shill::kAddressProperty, device->mac_address());
573 }
574 }
575 scoped_ptr<base::DictionaryValue> dictionary =
576 onc::TranslateShillServiceToONCPart(
577 *shill_properties_with_device, &onc::kNetworkWithStateSignature);
578 311
579 dictionary->SetString(kNetworkInfoKeyServicePath, network->path()); 312 dictionary->SetString(kNetworkInfoKeyServicePath, network->path());
580 dictionary->SetString( 313 dictionary->SetString(
581 kTagErrorMessage, 314 kTagErrorMessage,
582 ash::network_connect::ErrorString(network->error(), network->path())); 315 ash::network_connect::ErrorString(network->error(), network->path()));
583 316
584 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty()); 317 dictionary->SetBoolean(kTagRemembered, !network->profile_path().empty());
585 bool shared = !network->IsPrivate(); 318 bool shared = !network->IsPrivate();
586 dictionary->SetBoolean(kTagShared, shared); 319 dictionary->SetBoolean(kTagShared, shared);
587 320
588 const std::string& type = network->type(); 321 const std::string& type = network->type();
589 322
590 const NetworkState* connected_network = 323 const NetworkState* connected_network =
591 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( 324 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
592 NetworkTypePattern::Primitive(type)); 325 NetworkTypePattern::Primitive(type));
593 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); 326 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL);
594 327
595 if (type == shill::kTypeCellular) 328 if (type == shill::kTypeCellular)
596 PopulateCellularDetails(network, dictionary.get()); 329 PopulateCellularDetails(network, dictionary.get());
597 else if (type == shill::kTypeVPN)
598 PopulateVPNDetails(network, shill_properties, dictionary.get());
599 330
600 return dictionary.Pass(); 331 return dictionary.Pass();
601 } 332 }
602 333
603 // Helper methods for SetIPConfigProperties 334 // Helper methods for SetIPConfigProperties
604 bool AppendPropertyKeyIfPresent(const std::string& key, 335 bool AppendPropertyKeyIfPresent(const std::string& key,
605 const base::DictionaryValue& old_properties, 336 const base::DictionaryValue& old_properties,
606 std::vector<std::string>* property_keys) { 337 std::vector<std::string>* property_keys) {
607 if (old_properties.HasKey(key)) { 338 if (old_properties.HasKey(key)) {
608 property_keys->push_back(key); 339 property_keys->push_back(key);
(...skipping 362 matching lines...) Expand 10 before | Expand all | Expand 10 after
971 } 702 }
972 703
973 void InternetOptionsHandler::RefreshNetworkData() { 704 void InternetOptionsHandler::RefreshNetworkData() {
974 base::DictionaryValue dictionary; 705 base::DictionaryValue dictionary;
975 FillNetworkInfo(&dictionary); 706 FillNetworkInfo(&dictionary);
976 web_ui()->CallJavascriptFunction(kRefreshNetworkDataFunction, dictionary); 707 web_ui()->CallJavascriptFunction(kRefreshNetworkDataFunction, dictionary);
977 } 708 }
978 709
979 void InternetOptionsHandler::UpdateConnectionData( 710 void InternetOptionsHandler::UpdateConnectionData(
980 const std::string& service_path) { 711 const std::string& service_path) {
981 NetworkHandler::Get()->network_configuration_handler()->GetProperties( 712 NetworkHandler::Get()
982 service_path, 713 ->managed_network_configuration_handler()
983 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback, 714 ->GetManagedProperties(
984 weak_factory_.GetWeakPtr()), 715 LoginState::Get()->primary_user_hash(),
985 base::Bind(&ShillError, "UpdateConnectionData")); 716 service_path,
717 base::Bind(&InternetOptionsHandler::UpdateConnectionDataCallback,
718 weak_factory_.GetWeakPtr()),
719 base::Bind(&ShillError, "UpdateConnectionData"));
986 } 720 }
987 721
988 void InternetOptionsHandler::UpdateConnectionDataCallback( 722 void InternetOptionsHandler::UpdateConnectionDataCallback(
989 const std::string& service_path, 723 const std::string& service_path,
990 const base::DictionaryValue& shill_properties) { 724 const base::DictionaryValue& onc_properties) {
991 const NetworkState* network = GetNetworkState(service_path); 725 const NetworkState* network = GetNetworkState(service_path);
992 if (!network) 726 if (!network)
993 return; 727 return;
994 scoped_ptr<base::DictionaryValue> dictionary = 728 scoped_ptr<base::DictionaryValue> dictionary =
995 PopulateConnectionDetails(network, shill_properties); 729 PopulateConnectionDetails(network, onc_properties);
996 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, *dictionary); 730 web_ui()->CallJavascriptFunction(kUpdateConnectionDataFunction, *dictionary);
997 } 731 }
998 732
999 void InternetOptionsHandler::UpdateCarrier() { 733 void InternetOptionsHandler::UpdateCarrier() {
1000 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction); 734 web_ui()->CallJavascriptFunction(kUpdateCarrierFunction);
1001 } 735 }
1002 736
1003 void InternetOptionsHandler::DeviceListChanged() { 737 void InternetOptionsHandler::DeviceListChanged() {
1004 if (!web_ui()) 738 if (!web_ui())
1005 return; 739 return;
(...skipping 179 matching lines...) Expand 10 before | Expand all | Expand 10 after
1185 callback = base::Bind(&RequestReconnect, service_path, GetNativeWindow()); 919 callback = base::Bind(&RequestReconnect, service_path, GetNativeWindow());
1186 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs( 920 NetworkHandler::Get()->network_device_handler()->RequestRefreshIPConfigs(
1187 device_path, 921 device_path,
1188 callback, 922 callback,
1189 base::Bind(&ShillError, "RequestRefreshIPConfigs")); 923 base::Bind(&ShillError, "RequestRefreshIPConfigs"));
1190 } 924 }
1191 } 925 }
1192 926
1193 void InternetOptionsHandler::PopulateDictionaryDetailsCallback( 927 void InternetOptionsHandler::PopulateDictionaryDetailsCallback(
1194 const std::string& service_path, 928 const std::string& service_path,
1195 const base::DictionaryValue& shill_properties) { 929 const base::DictionaryValue& onc_properties) {
1196 const NetworkState* network = GetNetworkState(service_path); 930 const NetworkState* network = GetNetworkState(service_path);
1197 if (!network) { 931 if (!network) {
1198 LOG(ERROR) << "Network properties not found: " << service_path; 932 LOG(ERROR) << "Network properties not found: " << service_path;
1199 return; 933 return;
1200 } 934 }
1201 935
1202 details_path_ = service_path; 936 details_path_ = service_path;
1203 937
1204 scoped_ptr<base::DictionaryValue> dictionary = 938 scoped_ptr<base::DictionaryValue> dictionary =
1205 PopulateConnectionDetails(network, shill_properties); 939 PopulateConnectionDetails(network, onc_properties);
1206 940
1207 ::onc::ONCSource onc_source = ::onc::ONC_SOURCE_NONE;
1208 const base::DictionaryValue* onc =
1209 onc::FindPolicyForActiveUser(network->guid(), &onc_source);
1210 const NetworkPropertyUIData property_ui_data(onc_source);
1211
1212 // IP config
1213 scoped_ptr<base::DictionaryValue> ipconfig_dhcp(new base::DictionaryValue);
1214 ipconfig_dhcp->SetString(kIpConfigAddress, network->ip_address());
1215 ipconfig_dhcp->SetString(kIpConfigNetmask, network->GetNetmask());
1216 ipconfig_dhcp->SetString(kIpConfigGateway, network->gateway());
1217 std::string ipconfig_name_servers = network->GetDnsServersAsString();
1218 ipconfig_dhcp->SetString(kIpConfigNameServers, ipconfig_name_servers);
1219 ipconfig_dhcp->SetString(kIpConfigWebProxyAutoDiscoveryUrl,
1220 network->web_proxy_auto_discovery_url().spec());
1221 SetValueDictionary(kDictionaryIpConfig,
1222 ipconfig_dhcp.release(),
1223 property_ui_data,
1224 dictionary.get());
1225
1226 std::string name_server_type = kNameServerTypeAutomatic;
1227 int automatic_ip_config = 0;
1228 scoped_ptr<base::DictionaryValue> static_ip_dict(
1229 BuildIPInfoDictionary(shill_properties, true, &automatic_ip_config));
1230 dictionary->SetBoolean(kIpConfigAutoConfig, automatic_ip_config == 0);
1231 DCHECK(automatic_ip_config == 3 || automatic_ip_config == 0)
1232 << "UI doesn't support automatic specification of individual "
1233 << "static IP parameters.";
1234 scoped_ptr<base::DictionaryValue> saved_ip_dict(
1235 BuildIPInfoDictionary(shill_properties, false, NULL));
1236 dictionary->Set(kDictionarySavedIp, saved_ip_dict.release());
1237
1238 // Determine what kind of name server setting we have by comparing the
1239 // StaticIP and Google values with the ipconfig values.
1240 std::string static_ip_nameservers;
1241 static_ip_dict->GetString(kIpConfigNameServers, &static_ip_nameservers);
1242 if (!static_ip_nameservers.empty() &&
1243 static_ip_nameservers == ipconfig_name_servers) {
1244 name_server_type = kNameServerTypeUser;
1245 }
1246 if (ipconfig_name_servers == kGoogleNameServers) {
1247 name_server_type = kNameServerTypeGoogle;
1248 }
1249 SetValueDictionary(kDictionaryStaticIp,
1250 static_ip_dict.release(),
1251 property_ui_data,
1252 dictionary.get());
1253
1254 dictionary->SetString(kTagNameServerType, name_server_type);
1255 dictionary->SetString(kTagNameServersGoogle, kGoogleNameServers);
1256
1257 int priority = 0;
1258 shill_properties.GetIntegerWithoutPathExpansion(
1259 shill::kPriorityProperty, &priority);
1260 SetManagedValueDictionary(network->guid(),
1261 ::onc::network_config::kPriority,
1262 base::FundamentalValue(priority),
1263 ::onc::network_config::kPriority,
1264 dictionary.get());
1265
1266 std::string onc_path_to_auto_connect;
1267 if (network->Matches(NetworkTypePattern::WiFi())) { 941 if (network->Matches(NetworkTypePattern::WiFi())) {
1268 content::RecordAction( 942 content::RecordAction(
1269 base::UserMetricsAction("Options_NetworkShowDetailsWifi")); 943 base::UserMetricsAction("Options_NetworkShowDetailsWifi"));
1270 if (network->IsConnectedState()) { 944 if (network->IsConnectedState()) {
1271 content::RecordAction( 945 content::RecordAction(
1272 base::UserMetricsAction("Options_NetworkShowDetailsWifiConnected")); 946 base::UserMetricsAction("Options_NetworkShowDetailsWifiConnected"));
1273 } 947 }
1274 onc_path_to_auto_connect =
1275 ::onc::network_config::WifiProperty(::onc::wifi::kAutoConnect);
1276 } else if (network->Matches(NetworkTypePattern::VPN())) { 948 } else if (network->Matches(NetworkTypePattern::VPN())) {
1277 content::RecordAction( 949 content::RecordAction(
1278 base::UserMetricsAction("Options_NetworkShowDetailsVPN")); 950 base::UserMetricsAction("Options_NetworkShowDetailsVPN"));
1279 if (network->IsConnectedState()) { 951 if (network->IsConnectedState()) {
1280 content::RecordAction( 952 content::RecordAction(
1281 base::UserMetricsAction("Options_NetworkShowDetailsVPNConnected")); 953 base::UserMetricsAction("Options_NetworkShowDetailsVPNConnected"));
1282 } 954 }
1283 onc_path_to_auto_connect = ::onc::network_config::VpnProperty(
1284 ::onc::vpn::kAutoConnect);
1285 } else if (network->Matches(NetworkTypePattern::Cellular())) { 955 } else if (network->Matches(NetworkTypePattern::Cellular())) {
1286 content::RecordAction( 956 content::RecordAction(
1287 base::UserMetricsAction("Options_NetworkShowDetailsCellular")); 957 base::UserMetricsAction("Options_NetworkShowDetailsCellular"));
1288 if (network->IsConnectedState()) { 958 if (network->IsConnectedState()) {
1289 content::RecordAction(base::UserMetricsAction( 959 content::RecordAction(base::UserMetricsAction(
1290 "Options_NetworkShowDetailsCellularConnected")); 960 "Options_NetworkShowDetailsCellularConnected"));
1291 } 961 }
1292 } 962 }
1293 963
1294 if (!onc_path_to_auto_connect.empty()) {
1295 bool auto_connect = false;
1296 shill_properties.GetBooleanWithoutPathExpansion(
1297 shill::kAutoConnectProperty, &auto_connect);
1298
1299 base::FundamentalValue auto_connect_value(auto_connect);
1300 ::onc::ONCSource auto_connect_onc_source = onc_source;
1301
1302 DCHECK_EQ(onc == NULL, onc_source == ::onc::ONC_SOURCE_NONE);
1303 bool auto_connect_recommended =
1304 auto_connect_onc_source != ::onc::ONC_SOURCE_NONE &&
1305 onc::IsRecommendedValue(onc, onc_path_to_auto_connect);
1306 // If a policy exists, |auto_connect_default_value| will contain either a
1307 // recommended value (if |auto_connect_recommended| is true) or an enforced
1308 // value (if |auto_connect_recommended| is false).
1309 const base::Value* auto_connect_default_value = NULL;
1310 if (onc)
1311 onc->Get(onc_path_to_auto_connect, &auto_connect_default_value);
1312
1313 // Autoconnect can be controlled by the GlobalNetworkConfiguration of the
1314 // ONC policy.
1315 if (auto_connect_onc_source == ::onc::ONC_SOURCE_NONE &&
1316 onc::PolicyAllowsOnlyPolicyNetworksToAutoconnect(
1317 network->IsPrivate())) {
1318 auto_connect_recommended = false;
1319 auto_connect_onc_source = network->IsPrivate()
1320 ? ::onc::ONC_SOURCE_USER_POLICY
1321 : ::onc::ONC_SOURCE_DEVICE_POLICY;
1322 if (auto_connect) {
1323 LOG(WARNING) << "Policy prevents autoconnect, but value is True.";
1324 auto_connect_value = base::FundamentalValue(false);
1325 }
1326 }
1327 SetManagedValueDictionaryEx(shill::kAutoConnectProperty,
1328 auto_connect_value,
1329 auto_connect_onc_source,
1330 auto_connect_recommended,
1331 auto_connect_default_value,
1332 dictionary.get());
1333 }
1334
1335 // Show details dialog 964 // Show details dialog
1336 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary); 965 web_ui()->CallJavascriptFunction(kShowDetailedInfoFunction, *dictionary);
1337 } 966 }
1338 967
1339 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const { 968 gfx::NativeWindow InternetOptionsHandler::GetNativeWindow() const {
1340 return web_ui()->GetWebContents()->GetTopLevelNativeWindow(); 969 return web_ui()->GetWebContents()->GetTopLevelNativeWindow();
1341 } 970 }
1342 971
1343 float InternetOptionsHandler::GetScaleFactor() const { 972 float InternetOptionsHandler::GetScaleFactor() const {
1344 return web_ui()->GetDeviceScaleFactor(); 973 return web_ui()->GetDeviceScaleFactor();
(...skipping 24 matching lines...) Expand all
1369 // Process commands that do not require an existing network. 998 // Process commands that do not require an existing network.
1370 if (command == kTagAddConnection) { 999 if (command == kTagAddConnection) {
1371 AddConnection(type); 1000 AddConnection(type);
1372 } else if (command == kTagForget) { 1001 } else if (command == kTagForget) {
1373 NetworkHandler::Get()->network_configuration_handler()-> 1002 NetworkHandler::Get()->network_configuration_handler()->
1374 RemoveConfiguration( 1003 RemoveConfiguration(
1375 service_path, 1004 service_path,
1376 base::Bind(&base::DoNothing), 1005 base::Bind(&base::DoNothing),
1377 base::Bind(&ShillError, "NetworkCommand: " + command)); 1006 base::Bind(&ShillError, "NetworkCommand: " + command));
1378 } else if (command == kTagOptions) { 1007 } else if (command == kTagOptions) {
1379 NetworkHandler::Get()->network_configuration_handler()->GetProperties( 1008 NetworkHandler::Get()
1380 service_path, 1009 ->managed_network_configuration_handler()
1381 base::Bind(&InternetOptionsHandler::PopulateDictionaryDetailsCallback, 1010 ->GetManagedProperties(
1382 weak_factory_.GetWeakPtr()), 1011 LoginState::Get()->primary_user_hash(),
1383 base::Bind(&ShillError, "NetworkCommand: " + command)); 1012 service_path,
1013 base::Bind(
1014 &InternetOptionsHandler::PopulateDictionaryDetailsCallback,
1015 weak_factory_.GetWeakPtr()),
1016 base::Bind(&ShillError, "NetworkCommand: " + command));
1384 } else if (command == kTagConnect) { 1017 } else if (command == kTagConnect) {
1385 const NetworkState* network = GetNetworkState(service_path); 1018 const NetworkState* network = GetNetworkState(service_path);
1386 if (network && network->type() == shill::kTypeWifi) 1019 if (network && network->type() == shill::kTypeWifi)
1387 content::RecordAction( 1020 content::RecordAction(
1388 base::UserMetricsAction("Options_NetworkConnectToWifi")); 1021 base::UserMetricsAction("Options_NetworkConnectToWifi"));
1389 else if (network && network->type() == shill::kTypeVPN) 1022 else if (network && network->type() == shill::kTypeVPN)
1390 content::RecordAction( 1023 content::RecordAction(
1391 base::UserMetricsAction("Options_NetworkConnectToVPN")); 1024 base::UserMetricsAction("Options_NetworkConnectToVPN"));
1392 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow()); 1025 ash::network_connect::ConnectToNetwork(service_path, GetNativeWindow());
1393 } else if (command == kTagDisconnect) { 1026 } else if (command == kTagDisconnect) {
(...skipping 130 matching lines...) Expand 10 before | Expand all | Expand 10 after
1524 dictionary->SetBoolean( 1157 dictionary->SetBoolean(
1525 kTagWimaxAvailable, 1158 kTagWimaxAvailable,
1526 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); 1159 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax()));
1527 dictionary->SetBoolean( 1160 dictionary->SetBoolean(
1528 kTagWimaxEnabled, 1161 kTagWimaxEnabled,
1529 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); 1162 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax()));
1530 } 1163 }
1531 1164
1532 } // namespace options 1165 } // namespace options
1533 } // namespace chromeos 1166 } // namespace chromeos
OLDNEW
« no previous file with comments | « chrome/browser/resources/options/chromeos/internet_detail.js ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698