OLD | NEW |
---|---|
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 113 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
124 const char kSetIPConfigMessage[] = "setIPConfig"; | 124 const char kSetIPConfigMessage[] = "setIPConfig"; |
125 const char kSetPreferNetworkMessage[] = "setPreferNetwork"; | 125 const char kSetPreferNetworkMessage[] = "setPreferNetwork"; |
126 const char kSetServerHostname[] = "setServerHostname"; | 126 const char kSetServerHostname[] = "setServerHostname"; |
127 const char kSetSimCardLockMessage[] = "setSimCardLock"; | 127 const char kSetSimCardLockMessage[] = "setSimCardLock"; |
128 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo"; | 128 const char kShowMorePlanInfoMessage[] = "showMorePlanInfo"; |
129 | 129 |
130 // These are strings used to communicate with JavaScript. | 130 // These are strings used to communicate with JavaScript. |
131 const char kTagActivate[] = "activate"; | 131 const char kTagActivate[] = "activate"; |
132 const char kTagActivationState[] = "activationState"; | 132 const char kTagActivationState[] = "activationState"; |
133 const char kTagAddConnection[] = "add"; | 133 const char kTagAddConnection[] = "add"; |
134 const char kTagApn[] = "apn"; | |
135 const char kTagCarrierSelectFlag[] = "showCarrierSelect"; | 134 const char kTagCarrierSelectFlag[] = "showCarrierSelect"; |
136 const char kTagCarrierUrl[] = "carrierUrl"; | 135 const char kTagCarrierUrl[] = "carrierUrl"; |
137 const char kTagCellularAvailable[] = "cellularAvailable"; | 136 const char kTagCellularAvailable[] = "cellularAvailable"; |
138 const char kTagCellularEnabled[] = "cellularEnabled"; | 137 const char kTagCellularEnabled[] = "cellularEnabled"; |
139 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; | 138 const char kTagCellularSupportsScan[] = "cellularSupportsScan"; |
140 const char kTagConfigure[] = "configure"; | 139 const char kTagConfigure[] = "configure"; |
141 const char kTagConnect[] = "connect"; | 140 const char kTagConnect[] = "connect"; |
142 const char kTagControlledBy[] = "controlledBy"; | 141 const char kTagControlledBy[] = "controlledBy"; |
143 const char kTagDeviceConnected[] = "deviceConnected"; | 142 const char kTagDeviceConnected[] = "deviceConnected"; |
144 const char kTagDisconnect[] = "disconnect"; | 143 const char kTagDisconnect[] = "disconnect"; |
145 const char kTagErrorMessage[] = "errorMessage"; | 144 const char kTagErrorMessage[] = "errorMessage"; |
146 const char kTagForget[] = "forget"; | 145 const char kTagForget[] = "forget"; |
147 const char kTagLanguage[] = "language"; | 146 const char kTagLanguage[] = "language"; |
148 const char kTagLastGoodApn[] = "lastGoodApn"; | |
149 const char kTagLocalizedName[] = "localizedName"; | 147 const char kTagLocalizedName[] = "localizedName"; |
150 const char kTagName[] = "name"; | 148 const char kTagName[] = "name"; |
151 const char kTagNameServersGoogle[] = "nameServersGoogle"; | 149 const char kTagNameServersGoogle[] = "nameServersGoogle"; |
152 const char kTagNameServerType[] = "nameServerType"; | 150 const char kTagNameServerType[] = "nameServerType"; |
153 const char kTagNetworkId[] = "networkId"; | |
154 const char kTagOptions[] = "options"; | 151 const char kTagOptions[] = "options"; |
155 const char kTagPassword[] = "password"; | 152 const char kTagPassword[] = "password"; |
156 const char kTagPolicy[] = "policy"; | 153 const char kTagPolicy[] = "policy"; |
157 const char kTagProviderApnList[] = "providerApnList"; | |
158 const char kTagRecommended[] = "recommended"; | 154 const char kTagRecommended[] = "recommended"; |
159 const char kTagRecommendedValue[] = "recommendedValue"; | 155 const char kTagRecommendedValue[] = "recommendedValue"; |
160 const char kTagRemembered[] = "remembered"; | 156 const char kTagRemembered[] = "remembered"; |
161 const char kTagRememberedList[] = "rememberedList"; | 157 const char kTagRememberedList[] = "rememberedList"; |
162 const char kTagRestrictedPool[] = "restrictedPool"; | 158 const char kTagRestrictedPool[] = "restrictedPool"; |
163 const char kTagRoamingState[] = "roamingState"; | 159 const char kTagRoamingState[] = "roamingState"; |
164 const char kTagCarriers[] = "carriers"; | 160 const char kTagCarriers[] = "carriers"; |
165 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex"; | 161 const char kTagCurrentCarrierIndex[] = "currentCarrierIndex"; |
166 const char kTagShared[] = "shared"; | 162 const char kTagShared[] = "shared"; |
167 const char kTagShowActivateButton[] = "showActivateButton"; | 163 const char kTagShowActivateButton[] = "showActivateButton"; |
168 const char kTagShowViewAccountButton[] = "showViewAccountButton"; | 164 const char kTagShowViewAccountButton[] = "showViewAccountButton"; |
169 const char kTagSimCardLockEnabled[] = "simCardLockEnabled"; | |
170 const char kTagSupportUrl[] = "supportUrl"; | |
171 const char kTagTrue[] = "true"; | 165 const char kTagTrue[] = "true"; |
172 const char kTagUsername[] = "username"; | 166 const char kTagUsername[] = "username"; |
173 const char kTagValue[] = "value"; | 167 const char kTagValue[] = "value"; |
174 const char kTagVpnList[] = "vpnList"; | 168 const char kTagVpnList[] = "vpnList"; |
175 const char kTagWifiAvailable[] = "wifiAvailable"; | 169 const char kTagWifiAvailable[] = "wifiAvailable"; |
176 const char kTagWifiEnabled[] = "wifiEnabled"; | 170 const char kTagWifiEnabled[] = "wifiEnabled"; |
177 const char kTagWimaxAvailable[] = "wimaxAvailable"; | 171 const char kTagWimaxAvailable[] = "wimaxAvailable"; |
178 const char kTagWimaxEnabled[] = "wimaxEnabled"; | 172 const char kTagWimaxEnabled[] = "wimaxEnabled"; |
179 const char kTagWiredList[] = "wiredList"; | 173 const char kTagWiredList[] = "wiredList"; |
180 const char kTagWirelessList[] = "wirelessList"; | 174 const char kTagWirelessList[] = "wirelessList"; |
(...skipping 318 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
499 // the Generic UMTS carrier option if present. | 493 // the Generic UMTS carrier option if present. |
500 if (gsm && (value == shill::kCarrierGenericUMTS)) | 494 if (gsm && (value == shill::kCarrierGenericUMTS)) |
501 return index; | 495 return index; |
502 // For other carriers, the service name will match the carrier name. | 496 // For other carriers, the service name will match the carrier name. |
503 if (value == device->carrier()) | 497 if (value == device->carrier()) |
504 return index; | 498 return index; |
505 } | 499 } |
506 return -1; | 500 return -1; |
507 } | 501 } |
508 | 502 |
509 void CreateDictionaryFromCellularApn(const base::DictionaryValue* apn, | |
510 base::DictionaryValue* dictionary) { | |
511 CopyStringFromDictionary(*apn, shill::kApnProperty, kTagApn, dictionary); | |
512 CopyStringFromDictionary( | |
513 *apn, shill::kApnNetworkIdProperty, kTagNetworkId, dictionary); | |
514 CopyStringFromDictionary( | |
515 *apn, shill::kApnUsernameProperty, kTagUsername, dictionary); | |
516 CopyStringFromDictionary( | |
517 *apn, shill::kApnPasswordProperty, kTagPassword, dictionary); | |
518 CopyStringFromDictionary(*apn, shill::kApnNameProperty, kTagName, dictionary); | |
519 CopyStringFromDictionary( | |
520 *apn, shill::kApnLocalizedNameProperty, kTagLocalizedName, dictionary); | |
521 CopyStringFromDictionary( | |
522 *apn, shill::kApnLanguageProperty, kTagLanguage, dictionary); | |
523 } | |
524 | |
525 void PopulateCellularDetails(const NetworkState* cellular, | 503 void PopulateCellularDetails(const NetworkState* cellular, |
526 const base::DictionaryValue& shill_properties, | |
527 base::DictionaryValue* dictionary) { | 504 base::DictionaryValue* dictionary) { |
528 dictionary->SetBoolean(kTagCarrierSelectFlag, | 505 dictionary->SetBoolean(kTagCarrierSelectFlag, |
529 CommandLine::ForCurrentProcess()->HasSwitch( | 506 CommandLine::ForCurrentProcess()->HasSwitch( |
530 chromeos::switches::kEnableCarrierSwitching)); | 507 chromeos::switches::kEnableCarrierSwitching)); |
531 // Cellular network / connection settings. | 508 // Cellular network / connection settings. |
532 dictionary->SetString(kTagActivationState, | 509 dictionary->SetString(kTagActivationState, |
533 internet_options_strings::ActivationStateString( | 510 internet_options_strings::ActivationStateString( |
534 cellular->activation_state())); | 511 cellular->activation_state())); |
535 dictionary->SetString(kTagRoamingState, | 512 dictionary->SetString(kTagRoamingState, |
536 internet_options_strings::RoamingStateString( | 513 internet_options_strings::RoamingStateString( |
537 cellular->roaming())); | 514 cellular->roaming())); |
538 dictionary->SetString(kTagRestrictedPool, | 515 dictionary->SetString(kTagRestrictedPool, |
539 internet_options_strings::RestrictedStateString( | 516 internet_options_strings::RestrictedStateString( |
540 cellular->connection_state())); | 517 cellular->connection_state())); |
541 | 518 |
542 const base::DictionaryValue* olp = NULL; | |
543 if (shill_properties.GetDictionaryWithoutPathExpansion( | |
544 shill::kPaymentPortalProperty, &olp)) { | |
545 std::string url; | |
546 olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url); | |
547 dictionary->SetString(kTagSupportUrl, url); | |
stevenjb
2014/08/21 23:06:58
This is unused in the JS code.
| |
548 } | |
549 | |
550 base::DictionaryValue* apn = new base::DictionaryValue; | |
551 const base::DictionaryValue* source_apn = NULL; | |
552 if (shill_properties.GetDictionaryWithoutPathExpansion( | |
553 shill::kCellularApnProperty, &source_apn)) { | |
554 CreateDictionaryFromCellularApn(source_apn, apn); | |
555 } | |
556 dictionary->Set(kTagApn, apn); | |
557 | |
558 base::DictionaryValue* last_good_apn = new base::DictionaryValue; | |
559 if (shill_properties.GetDictionaryWithoutPathExpansion( | |
560 shill::kCellularLastGoodApnProperty, &source_apn)) { | |
561 CreateDictionaryFromCellularApn(source_apn, last_good_apn); | |
562 } | |
563 dictionary->Set(kTagLastGoodApn, last_good_apn); | |
564 | |
565 // These default to empty and are only set if device != NULL. | 519 // These default to empty and are only set if device != NULL. |
566 std::string carrier_id; | 520 std::string carrier_id; |
567 std::string mdn; | 521 std::string mdn; |
568 | 522 |
569 // Device settings. | 523 // Device settings. |
570 const DeviceState* device = | 524 const DeviceState* device = |
571 NetworkHandler::Get()->network_state_handler()->GetDeviceState( | 525 NetworkHandler::Get()->network_state_handler()->GetDeviceState( |
572 cellular->device_path()); | 526 cellular->device_path()); |
573 if (device) { | 527 if (device) { |
574 const base::DictionaryValue& device_properties = device->properties(); | 528 const base::DictionaryValue& device_properties = device->properties(); |
575 ::onc::ONCSource onc_source; | |
576 NetworkHandler::Get()->managed_network_configuration_handler()-> | |
577 FindPolicyByGUID(LoginState::Get()->primary_user_hash(), | |
578 cellular->guid(), &onc_source); | |
579 const NetworkPropertyUIData cellular_property_ui_data(onc_source); | |
580 SetValueDictionary(kTagSimCardLockEnabled, | |
581 new base::FundamentalValue(device->sim_lock_enabled()), | |
582 cellular_property_ui_data, | |
583 dictionary); | |
584 | 529 |
585 carrier_id = device->home_provider_id(); | 530 carrier_id = device->home_provider_id(); |
586 device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn); | 531 device_properties.GetStringWithoutPathExpansion(shill::kMdnProperty, &mdn); |
587 | 532 |
588 MobileConfig* config = MobileConfig::GetInstance(); | 533 MobileConfig* config = MobileConfig::GetInstance(); |
589 if (config->IsReady()) { | 534 if (config->IsReady()) { |
590 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id); | 535 const MobileConfig::Carrier* carrier = config->GetCarrier(carrier_id); |
591 if (carrier && !carrier->top_up_url().empty()) | 536 if (carrier && !carrier->top_up_url().empty()) |
592 dictionary->SetString(kTagCarrierUrl, carrier->top_up_url()); | 537 dictionary->SetString(kTagCarrierUrl, carrier->top_up_url()); |
593 } | 538 } |
594 | 539 |
595 base::ListValue* apn_list_value = new base::ListValue(); | |
596 const base::ListValue* apn_list; | |
597 if (device_properties.GetListWithoutPathExpansion( | |
598 shill::kCellularApnListProperty, &apn_list)) { | |
599 for (base::ListValue::const_iterator iter = apn_list->begin(); | |
600 iter != apn_list->end(); | |
601 ++iter) { | |
602 const base::DictionaryValue* dict; | |
603 if ((*iter)->GetAsDictionary(&dict)) { | |
604 base::DictionaryValue* apn = new base::DictionaryValue; | |
605 CreateDictionaryFromCellularApn(dict, apn); | |
606 apn_list_value->Append(apn); | |
607 } | |
608 } | |
609 } | |
610 SetValueDictionary(kTagProviderApnList, | |
611 apn_list_value, | |
612 cellular_property_ui_data, | |
613 dictionary); | |
614 const base::ListValue* supported_carriers; | 540 const base::ListValue* supported_carriers; |
615 if (device_properties.GetListWithoutPathExpansion( | 541 if (device_properties.GetListWithoutPathExpansion( |
616 shill::kSupportedCarriersProperty, &supported_carriers)) { | 542 shill::kSupportedCarriersProperty, &supported_carriers)) { |
617 dictionary->Set(kTagCarriers, supported_carriers->DeepCopy()); | 543 dictionary->Set(kTagCarriers, supported_carriers->DeepCopy()); |
618 dictionary->SetInteger( | 544 dictionary->SetInteger( |
619 kTagCurrentCarrierIndex, | 545 kTagCurrentCarrierIndex, |
620 FindCurrentCarrierIndex(supported_carriers, device)); | 546 FindCurrentCarrierIndex(supported_carriers, device)); |
621 } else { | 547 } else { |
622 // In case of any error, set the current carrier tag to -1 indicating | 548 // In case of any error, set the current carrier tag to -1 indicating |
623 // to the JS code to fallback to a single carrier. | 549 // to the JS code to fallback to a single carrier. |
624 dictionary->SetInteger(kTagCurrentCarrierIndex, -1); | 550 dictionary->SetInteger(kTagCurrentCarrierIndex, -1); |
625 } | 551 } |
626 } | 552 } |
627 | 553 |
628 // Don't show any account management related buttons if the activation | 554 // Don't show any account management related buttons if the activation |
629 // state is unknown or no payment portal URL is available. | 555 // state is unknown. |
630 std::string support_url; | 556 if (cellular->activation_state() == shill::kActivationStateUnknown) { |
631 if (cellular->activation_state() == shill::kActivationStateUnknown || | 557 VLOG(2) << "Activation state unknown. Don't display buttons."; |
632 !dictionary->GetString(kTagSupportUrl, &support_url) || | |
633 support_url.empty()) { | |
stevenjb
2014/08/21 23:06:58
Since the support URL is unused, it doesn't seem t
armansito
2014/08/22 00:56:45
Even though the settings JS isn't using it, I thin
stevenjb
2014/08/22 17:08:44
According to service_constants.h, kPaymentPortalPr
thieule
2014/08/22 19:13:04
We should be using the new kActivationType propert
stevenjb
2014/08/25 20:57:27
So... is there an additional check that we should
armansito
2014/08/25 21:48:50
Yeah...I wouldn't trust that. Then again I think t
stevenjb
2014/08/25 22:32:34
So, I looked at the code again and realized that m
| |
634 VLOG(2) << "No support URL is available. Don't display buttons."; | |
635 return; | 558 return; |
636 } | 559 } |
637 | 560 |
638 if (cellular->activation_state() != shill::kActivationStateActivating && | 561 if (cellular->activation_state() != shill::kActivationStateActivating && |
639 cellular->activation_state() != shill::kActivationStateActivated) { | 562 cellular->activation_state() != shill::kActivationStateActivated) { |
640 dictionary->SetBoolean(kTagShowActivateButton, true); | 563 dictionary->SetBoolean(kTagShowActivateButton, true); |
641 } else { | 564 } else { |
642 bool may_show_portal_button = false; | 565 bool may_show_portal_button = false; |
643 | 566 |
644 // If an online payment URL was provided by shill, then this means that the | 567 // Use MobileConfig to determine if the "View Account" should be shown. |
645 // "View Account" button should be shown for the current carrier. | 568 if (MobileConfig::GetInstance()->IsReady()) { |
646 if (olp) { | |
647 std::string url; | |
648 olp->GetStringWithoutPathExpansion(shill::kPaymentPortalURL, &url); | |
649 may_show_portal_button = !url.empty(); | |
650 } | |
651 // If no online payment URL was provided by shill, fall back to | |
652 // MobileConfig to determine if the "View Account" should be shown. | |
653 if (!may_show_portal_button && MobileConfig::GetInstance()->IsReady()) { | |
654 const MobileConfig::Carrier* carrier = | 569 const MobileConfig::Carrier* carrier = |
655 MobileConfig::GetInstance()->GetCarrier(carrier_id); | 570 MobileConfig::GetInstance()->GetCarrier(carrier_id); |
656 may_show_portal_button = carrier && carrier->show_portal_button(); | 571 may_show_portal_button = carrier && carrier->show_portal_button(); |
657 } | 572 } |
658 if (may_show_portal_button) { | 573 if (may_show_portal_button) { |
659 // The button should be shown for a LTE network even when the LTE network | 574 // The button should be shown for a LTE network even when the LTE network |
660 // is not connected, but CrOS is online. This is done to enable users to | 575 // is not connected, but CrOS is online. This is done to enable users to |
661 // update their plan even if they are out of credits. | 576 // update their plan even if they are out of credits. |
662 // The button should not be shown when the device's mdn is not set, | 577 // The button should not be shown when the device's mdn is not set, |
663 // because the network's proper portal url cannot be generated without it | 578 // because the network's proper portal url cannot be generated without it |
(...skipping 50 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
714 dictionary->SetBoolean(kTagShared, shared); | 629 dictionary->SetBoolean(kTagShared, shared); |
715 | 630 |
716 const std::string& type = network->type(); | 631 const std::string& type = network->type(); |
717 | 632 |
718 const NetworkState* connected_network = | 633 const NetworkState* connected_network = |
719 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( | 634 NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( |
720 NetworkTypePattern::Primitive(type)); | 635 NetworkTypePattern::Primitive(type)); |
721 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); | 636 dictionary->SetBoolean(kTagDeviceConnected, connected_network != NULL); |
722 | 637 |
723 if (type == shill::kTypeCellular) | 638 if (type == shill::kTypeCellular) |
724 PopulateCellularDetails(network, shill_properties, dictionary.get()); | 639 PopulateCellularDetails(network, dictionary.get()); |
725 else if (type == shill::kTypeVPN) | 640 else if (type == shill::kTypeVPN) |
726 PopulateVPNDetails(network, shill_properties, dictionary.get()); | 641 PopulateVPNDetails(network, shill_properties, dictionary.get()); |
727 | 642 |
728 return dictionary.Pass(); | 643 return dictionary.Pass(); |
729 } | 644 } |
730 | 645 |
731 // Helper methods for SetIPConfigProperties | 646 // Helper methods for SetIPConfigProperties |
732 bool AppendPropertyKeyIfPresent(const std::string& key, | 647 bool AppendPropertyKeyIfPresent(const std::string& key, |
733 const base::DictionaryValue& old_properties, | 648 const base::DictionaryValue& old_properties, |
734 std::vector<std::string>* property_keys) { | 649 std::vector<std::string>* property_keys) { |
(...skipping 917 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
1652 dictionary->SetBoolean( | 1567 dictionary->SetBoolean( |
1653 kTagWimaxAvailable, | 1568 kTagWimaxAvailable, |
1654 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); | 1569 handler->IsTechnologyAvailable(NetworkTypePattern::Wimax())); |
1655 dictionary->SetBoolean( | 1570 dictionary->SetBoolean( |
1656 kTagWimaxEnabled, | 1571 kTagWimaxEnabled, |
1657 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); | 1572 handler->IsTechnologyEnabled(NetworkTypePattern::Wimax())); |
1658 } | 1573 } |
1659 | 1574 |
1660 } // namespace options | 1575 } // namespace options |
1661 } // namespace chromeos | 1576 } // namespace chromeos |
OLD | NEW |