OLD | NEW |
---|---|
1 // Copyright 2016 The Chromium Authors. All rights reserved. | 1 // Copyright 2016 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 "ash/system/network/network_list.h" | 5 #include "ash/system/network/network_list.h" |
6 | 6 |
7 #include <memory> | 7 #include <memory> |
8 | 8 |
9 #include "ash/shell.h" | 9 #include "ash/shell.h" |
10 #include "ash/shell_port.h" | 10 #include "ash/shell_port.h" |
(...skipping 160 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
171 views::ToggleButton* toggle_; | 171 views::ToggleButton* toggle_; |
172 | 172 |
173 // TrayPopupItemStyle used to configure labels and buttons. | 173 // TrayPopupItemStyle used to configure labels and buttons. |
174 std::unique_ptr<TrayPopupItemStyle> style_; | 174 std::unique_ptr<TrayPopupItemStyle> style_; |
175 | 175 |
176 DISALLOW_COPY_AND_ASSIGN(SectionHeaderRowView); | 176 DISALLOW_COPY_AND_ASSIGN(SectionHeaderRowView); |
177 }; | 177 }; |
178 | 178 |
179 namespace { | 179 namespace { |
180 | 180 |
181 class CellularHeaderRowView : public NetworkListView::SectionHeaderRowView { | 181 class MobileHeaderRowView : public NetworkListView::SectionHeaderRowView { |
182 public: | 182 public: |
183 CellularHeaderRowView() | 183 MobileHeaderRowView() |
184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} | 184 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_MOBILE) {} |
185 | 185 |
186 ~CellularHeaderRowView() override {} | 186 ~MobileHeaderRowView() override {} |
187 | 187 |
188 const char* GetClassName() const override { return "CellularHeaderRowView"; } | 188 const char* GetClassName() const override { return "MobileHeaderRowView"; } |
189 | 189 |
190 protected: | 190 protected: |
191 void OnToggleToggled(bool is_on) override { | 191 void OnToggleToggled(bool is_on) override { |
192 NetworkStateHandler* handler = | 192 NetworkStateHandler* handler = |
193 NetworkHandler::Get()->network_state_handler(); | 193 NetworkHandler::Get()->network_state_handler(); |
194 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, | 194 // The Mobile network type contains both Cellular and Tether technologies, |
195 chromeos::network_handler::ErrorCallback()); | 195 // though one or both of these may be unavailable. When Cellular technology |
196 // is available, the enabled value of Tether depends on the enabled value of | |
197 // Cellular, so the toggle should only explicitly change the enabled value | |
198 // of Cellular. | |
199 // However, if Cellular technology is not available but Tether technology is | |
200 // available, the toggle should explicitly change the enabled value of | |
201 // Tether. | |
stevenjb
2017/06/07 23:10:30
Rather than putting this subtle logic in the UI co
| |
202 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | |
203 handler->SetTechnologyEnabled(NetworkTypePattern::Cellular(), is_on, | |
204 chromeos::network_handler::ErrorCallback()); | |
205 } else { | |
206 DCHECK(handler->IsTechnologyAvailable(NetworkTypePattern::Tether())); | |
207 | |
208 handler->SetTechnologyEnabled(NetworkTypePattern::Tether(), is_on, | |
209 chromeos::network_handler::ErrorCallback()); | |
210 } | |
196 } | 211 } |
197 | 212 |
198 private: | 213 private: |
199 DISALLOW_COPY_AND_ASSIGN(CellularHeaderRowView); | 214 DISALLOW_COPY_AND_ASSIGN(MobileHeaderRowView); |
200 }; | 215 }; |
201 | 216 |
202 class TetherHeaderRowView : public NetworkListView::SectionHeaderRowView { | |
203 public: | |
204 TetherHeaderRowView() | |
205 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_TETHER) {} | |
206 | |
207 ~TetherHeaderRowView() override {} | |
208 | |
209 const char* GetClassName() const override { return "TetherHeaderRowView"; } | |
210 | |
211 protected: | |
212 void OnToggleToggled(bool is_on) override { | |
213 // TODO (hansberry): Persist toggle to settings/preferences. | |
214 } | |
215 | |
216 private: | |
217 DISALLOW_COPY_AND_ASSIGN(TetherHeaderRowView); | |
218 }; | |
219 | 217 |
220 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { | 218 class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { |
221 public: | 219 public: |
222 WifiHeaderRowView() | 220 WifiHeaderRowView() |
223 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), | 221 : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), |
224 join_(nullptr) {} | 222 join_(nullptr) {} |
225 | 223 |
226 ~WifiHeaderRowView() override {} | 224 ~WifiHeaderRowView() override {} |
227 | 225 |
228 void SetIsOn(bool enabled) override { | 226 void SetIsOn(bool enabled) override { |
(...skipping 60 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
289 }; | 287 }; |
290 | 288 |
291 } // namespace | 289 } // namespace |
292 | 290 |
293 // NetworkListView: | 291 // NetworkListView: |
294 | 292 |
295 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) | 293 NetworkListView::NetworkListView(SystemTrayItem* owner, LoginStatus login) |
296 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), | 294 : NetworkStateListDetailedView(owner, LIST_TYPE_NETWORK, login), |
297 needs_relayout_(false), | 295 needs_relayout_(false), |
298 no_wifi_networks_view_(nullptr), | 296 no_wifi_networks_view_(nullptr), |
299 no_cellular_networks_view_(nullptr), | 297 no_mobile_networks_view_(nullptr), |
300 cellular_header_view_(nullptr), | 298 mobile_header_view_(nullptr), |
301 tether_header_view_(nullptr), | |
302 wifi_header_view_(nullptr), | 299 wifi_header_view_(nullptr), |
303 cellular_separator_view_(nullptr), | 300 mobile_separator_view_(nullptr), |
304 tether_separator_view_(nullptr), | |
305 wifi_separator_view_(nullptr), | 301 wifi_separator_view_(nullptr), |
306 connection_warning_(nullptr) {} | 302 connection_warning_(nullptr) {} |
307 | 303 |
308 NetworkListView::~NetworkListView() { | 304 NetworkListView::~NetworkListView() { |
309 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 305 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
310 } | 306 } |
311 | 307 |
312 void NetworkListView::UpdateNetworkList() { | 308 void NetworkListView::UpdateNetworkList() { |
313 CHECK(scroll_content()); | 309 CHECK(scroll_content()); |
314 | 310 |
(...skipping 109 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
424 network, network_icon::ICON_TYPE_MENU_LIST); | 420 network, network_icon::ICON_TYPE_MENU_LIST); |
425 info->image = | 421 info->image = |
426 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 422 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
427 info->disable = | 423 info->disable = |
428 (network->activation_state() == shill::kActivationStateActivating) || | 424 (network->activation_state() == shill::kActivationStateActivating) || |
429 prohibited_by_policy; | 425 prohibited_by_policy; |
430 info->connected = network->IsConnectedState(); | 426 info->connected = network->IsConnectedState(); |
431 info->connecting = network->IsConnectingState(); | 427 info->connecting = network->IsConnectingState(); |
432 if (network->Matches(NetworkTypePattern::WiFi())) | 428 if (network->Matches(NetworkTypePattern::WiFi())) |
433 info->type = NetworkInfo::Type::WIFI; | 429 info->type = NetworkInfo::Type::WIFI; |
434 else if (network->Matches(NetworkTypePattern::Cellular())) | 430 else if (network->Matches(NetworkTypePattern::Mobile())) |
435 info->type = NetworkInfo::Type::CELLULAR; | 431 info->type = NetworkInfo::Type::MOBILE; |
436 else if (network->Matches(NetworkTypePattern::Tether())) | |
437 info->type = NetworkInfo::Type::TETHER; | |
438 if (prohibited_by_policy) { | 432 if (prohibited_by_policy) { |
439 info->tooltip = | 433 info->tooltip = |
440 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | 434 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); |
441 } | 435 } |
442 if (!animating && network->IsConnectingState()) | 436 if (!animating && network->IsConnectingState()) |
443 animating = true; | 437 animating = true; |
444 } | 438 } |
445 if (animating) | 439 if (animating) |
446 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 440 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
447 else | 441 else |
(...skipping 55 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
503 const bool using_proxy = NetworkHandler::Get()->ui_proxy_config_service() && | 497 const bool using_proxy = NetworkHandler::Get()->ui_proxy_config_service() && |
504 NetworkHandler::Get() | 498 NetworkHandler::Get() |
505 ->ui_proxy_config_service() | 499 ->ui_proxy_config_service() |
506 ->HasDefaultNetworkProxyConfigured(); | 500 ->HasDefaultNetworkProxyConfigured(); |
507 if (using_vpn || using_proxy) { | 501 if (using_vpn || using_proxy) { |
508 if (!connection_warning_) | 502 if (!connection_warning_) |
509 connection_warning_ = CreateConnectionWarning(); | 503 connection_warning_ = CreateConnectionWarning(); |
510 PlaceViewAtIndex(connection_warning_, index++); | 504 PlaceViewAtIndex(connection_warning_, index++); |
511 } | 505 } |
512 | 506 |
513 // First add high-priority networks (not Wi-Fi nor cellular). | 507 // First add high-priority networks (neither Wi-Fi nor Mobile). |
514 std::unique_ptr<std::set<std::string>> new_guids = | 508 std::unique_ptr<std::set<std::string>> new_guids = |
515 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); | 509 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
516 index += new_guids->size(); | 510 index += new_guids->size(); |
517 | 511 |
518 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 512 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular()) || |
519 index = UpdateSectionHeaderRow( | 513 handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { |
stevenjb
2017/06/07 23:10:30
We should also make IsTechnologyAvailable work cor
| |
520 NetworkTypePattern::Cellular(), | 514 bool is_enabled = |
521 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 515 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()) || |
522 &cellular_header_view_, &cellular_separator_view_); | 516 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()); |
stevenjb
2017/06/07 23:10:30
And IsTechnologyEnabled.
| |
517 | |
518 index = UpdateSectionHeaderRow(NetworkTypePattern::Cellular(), is_enabled, | |
stevenjb
2017/06/07 23:10:30
NetworkTypePattern::Mobile() should work here.
| |
519 index, &mobile_header_view_, | |
520 &mobile_separator_view_); | |
523 } | 521 } |
524 | 522 |
525 // Cellular initializing. | 523 // Cellular initializing. |
526 int cellular_message_id = network_icon::GetMobileUninitializedMsg(); | 524 int cellular_message_id = network_icon::GetMobileUninitializedMsg(); |
527 if (!cellular_message_id && | 525 if (!cellular_message_id && |
528 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && | 526 handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) && |
529 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { | 527 !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) { |
530 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; | 528 cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS; |
531 } | 529 } |
532 UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_); | 530 UpdateInfoLabel(cellular_message_id, index, &no_mobile_networks_view_); |
533 if (cellular_message_id) | 531 if (cellular_message_id) |
534 ++index; | 532 ++index; |
535 | 533 |
536 // Add cellular networks. | 534 // Add cellular and Tether networks. |
537 std::unique_ptr<std::set<std::string>> new_cellular_guids = | 535 std::unique_ptr<std::set<std::string>> new_cellular_guids = |
538 UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); | 536 UpdateNetworkChildren(NetworkInfo::Type::MOBILE, index); |
539 index += new_cellular_guids->size(); | 537 index += new_cellular_guids->size(); |
540 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); | 538 new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); |
541 | 539 |
542 // TODO (hansberry): Audit existing usage of NonVirtual and consider changing | |
543 // it to include Tether. See crbug.com/693647. | |
544 if (handler->IsTechnologyAvailable(NetworkTypePattern::Tether())) { | |
545 index = UpdateSectionHeaderRow( | |
546 NetworkTypePattern::Tether(), | |
547 handler->IsTechnologyEnabled(NetworkTypePattern::Tether()), index, | |
548 &tether_header_view_, &tether_separator_view_); | |
549 | |
550 // TODO (hansberry): Should a message similar to | |
551 // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is | |
552 // enabled but no networks are around? | |
553 | |
554 // Add Tether networks. | |
555 std::unique_ptr<std::set<std::string>> new_tether_guids = | |
556 UpdateNetworkChildren(NetworkInfo::Type::TETHER, index); | |
557 index += new_tether_guids->size(); | |
558 new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); | |
559 } | |
560 | |
561 index = UpdateSectionHeaderRow( | 540 index = UpdateSectionHeaderRow( |
562 NetworkTypePattern::WiFi(), | 541 NetworkTypePattern::WiFi(), |
563 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, | 542 handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, |
564 &wifi_header_view_, &wifi_separator_view_); | 543 &wifi_header_view_, &wifi_separator_view_); |
565 | 544 |
566 // "Wifi Enabled / Disabled". | 545 // "Wifi Enabled / Disabled". |
567 int wifi_message_id = 0; | 546 int wifi_message_id = 0; |
568 if (network_list_.empty()) { | 547 if (network_list_.empty()) { |
569 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) | 548 wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) |
570 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED | 549 ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED |
(...skipping 115 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
686 PlaceViewAtIndex(info_label, insertion_index); | 665 PlaceViewAtIndex(info_label, insertion_index); |
687 *info_label_ptr = info_label; | 666 *info_label_ptr = info_label; |
688 } | 667 } |
689 | 668 |
690 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, | 669 int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, |
691 bool enabled, | 670 bool enabled, |
692 int child_index, | 671 int child_index, |
693 SectionHeaderRowView** view, | 672 SectionHeaderRowView** view, |
694 views::Separator** separator_view) { | 673 views::Separator** separator_view) { |
695 if (!*view) { | 674 if (!*view) { |
696 if (pattern.Equals(NetworkTypePattern::Cellular())) | 675 if (pattern.MatchesPattern(NetworkTypePattern::Mobile())) |
697 *view = new CellularHeaderRowView(); | 676 *view = new MobileHeaderRowView(); |
698 else if (pattern.Equals(NetworkTypePattern::Tether())) | |
699 *view = new TetherHeaderRowView(); | |
700 else if (pattern.Equals(NetworkTypePattern::WiFi())) | 677 else if (pattern.Equals(NetworkTypePattern::WiFi())) |
701 *view = new WifiHeaderRowView(); | 678 *view = new WifiHeaderRowView(); |
702 else | 679 else |
703 NOTREACHED(); | 680 NOTREACHED(); |
704 (*view)->Init(enabled); | 681 (*view)->Init(enabled); |
705 } | 682 } |
706 // Show or hide a separator above the header. The separator should only be | 683 // Show or hide a separator above the header. The separator should only be |
707 // visible when the header row is not at the top of the list. | 684 // visible when the header row is not at the top of the list. |
708 if (child_index > 0) { | 685 if (child_index > 0) { |
709 if (!*separator_view) | 686 if (!*separator_view) |
(...skipping 51 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
761 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( | 738 TriView::Container::CENTER, views::CreateEmptyBorder(gfx::Insets( |
762 0, 0, 0, kTrayPopupLabelRightPadding))); | 739 0, 0, 0, kTrayPopupLabelRightPadding))); |
763 | 740 |
764 // Nothing to the right of the text. | 741 // Nothing to the right of the text. |
765 connection_warning->SetContainerVisible(TriView::Container::END, false); | 742 connection_warning->SetContainerVisible(TriView::Container::END, false); |
766 return connection_warning; | 743 return connection_warning; |
767 } | 744 } |
768 | 745 |
769 } // namespace tray | 746 } // namespace tray |
770 } // namespace ash | 747 } // namespace ash |
OLD | NEW |