Chromium Code Reviews| 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 <stddef.h> | 7 #include <stddef.h> |
| 8 | 8 |
| 9 #include "ash/shell.h" | |
| 9 #include "ash/strings/grit/ash_strings.h" | 10 #include "ash/strings/grit/ash_strings.h" |
| 10 #include "ash/system/network/network_icon.h" | 11 #include "ash/system/network/network_icon.h" |
| 11 #include "ash/system/network/network_icon_animation.h" | 12 #include "ash/system/network/network_icon_animation.h" |
| 12 #include "ash/system/network/network_list_delegate.h" | 13 #include "ash/system/network/network_list_delegate.h" |
| 14 #include "ash/system/networking_config_delegate.h" | |
| 13 #include "ash/system/tray/system_menu_button.h" | 15 #include "ash/system/tray/system_menu_button.h" |
| 16 #include "ash/system/tray/system_tray_delegate.h" | |
| 14 #include "ash/system/tray/tray_constants.h" | 17 #include "ash/system/tray/tray_constants.h" |
| 15 #include "ash/system/tray/tray_popup_item_style.h" | 18 #include "ash/system/tray/tray_popup_item_style.h" |
| 16 #include "ash/system/tray/tray_popup_utils.h" | 19 #include "ash/system/tray/tray_popup_utils.h" |
| 20 #include "ash/system/tray/tri_view.h" | |
| 17 #include "base/memory/ptr_util.h" | 21 #include "base/memory/ptr_util.h" |
| 18 #include "chromeos/dbus/dbus_thread_manager.h" | 22 #include "chromeos/dbus/dbus_thread_manager.h" |
| 19 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 23 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
| 20 #include "chromeos/dbus/power_manager_client.h" | 24 #include "chromeos/dbus/power_manager_client.h" |
| 21 #include "chromeos/login/login_state.h" | 25 #include "chromeos/login/login_state.h" |
| 22 #include "chromeos/network/managed_network_configuration_handler.h" | 26 #include "chromeos/network/managed_network_configuration_handler.h" |
| 23 #include "chromeos/network/network_state.h" | 27 #include "chromeos/network/network_state.h" |
| 24 #include "chromeos/network/network_state_handler.h" | 28 #include "chromeos/network/network_state_handler.h" |
| 25 #include "chromeos/network/network_state_handler_observer.h" | 29 #include "chromeos/network/network_state_handler_observer.h" |
| 26 #include "components/device_event_log/device_event_log.h" | 30 #include "components/device_event_log/device_event_log.h" |
| 27 #include "ui/base/l10n/l10n_util.h" | 31 #include "ui/base/l10n/l10n_util.h" |
| 28 #include "ui/base/resource/resource_bundle.h" | 32 #include "ui/base/resource/resource_bundle.h" |
| 29 #include "ui/gfx/color_palette.h" | 33 #include "ui/gfx/color_palette.h" |
| 30 #include "ui/gfx/font.h" | 34 #include "ui/gfx/font.h" |
| 31 #include "ui/gfx/paint_vector_icon.h" | 35 #include "ui/gfx/paint_vector_icon.h" |
| 36 #include "ui/views/background.h" | |
| 32 #include "ui/views/controls/button/toggle_button.h" | 37 #include "ui/views/controls/button/toggle_button.h" |
| 38 #include "ui/views/controls/image_view.h" | |
| 33 #include "ui/views/controls/label.h" | 39 #include "ui/views/controls/label.h" |
| 34 #include "ui/views/controls/separator.h" | 40 #include "ui/views/controls/separator.h" |
| 35 #include "ui/views/layout/box_layout.h" | 41 #include "ui/views/layout/box_layout.h" |
| 36 #include "ui/views/layout/fill_layout.h" | 42 #include "ui/views/layout/fill_layout.h" |
| 37 #include "ui/views/painter.h" | 43 #include "ui/views/painter.h" |
| 38 #include "ui/views/view.h" | 44 #include "ui/views/view.h" |
| 39 | 45 |
| 40 using chromeos::LoginState; | 46 using chromeos::LoginState; |
| 41 using chromeos::NetworkHandler; | 47 using chromeos::NetworkHandler; |
| 42 using chromeos::NetworkStateHandler; | 48 using chromeos::NetworkStateHandler; |
| (...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 282 NetworkListView::NetworkListView(NetworkListDelegate* delegate) | 288 NetworkListView::NetworkListView(NetworkListDelegate* delegate) |
| 283 : needs_relayout_(false), | 289 : needs_relayout_(false), |
| 284 delegate_(delegate), | 290 delegate_(delegate), |
| 285 no_wifi_networks_view_(nullptr), | 291 no_wifi_networks_view_(nullptr), |
| 286 no_cellular_networks_view_(nullptr), | 292 no_cellular_networks_view_(nullptr), |
| 287 cellular_header_view_(nullptr), | 293 cellular_header_view_(nullptr), |
| 288 tether_header_view_(nullptr), | 294 tether_header_view_(nullptr), |
| 289 wifi_header_view_(nullptr), | 295 wifi_header_view_(nullptr), |
| 290 cellular_separator_view_(nullptr), | 296 cellular_separator_view_(nullptr), |
| 291 tether_separator_view_(nullptr), | 297 tether_separator_view_(nullptr), |
| 292 wifi_separator_view_(nullptr) { | 298 wifi_separator_view_(nullptr), |
| 299 connection_warning_(nullptr) { | |
| 293 CHECK(delegate_); | 300 CHECK(delegate_); |
| 294 } | 301 } |
| 295 | 302 |
| 296 NetworkListView::~NetworkListView() { | 303 NetworkListView::~NetworkListView() { |
| 297 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 304 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 298 } | 305 } |
| 299 | 306 |
| 300 void NetworkListView::Update() { | 307 void NetworkListView::Update() { |
| 301 CHECK(container()); | 308 CHECK(container()); |
| 302 | 309 |
| (...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 473 container()->SizeToPreferredSize(); | 480 container()->SizeToPreferredSize(); |
| 474 delegate_->RelayoutScrollList(); | 481 delegate_->RelayoutScrollList(); |
| 475 if (selected_view) | 482 if (selected_view) |
| 476 container()->ScrollRectToVisible(selected_view->bounds()); | 483 container()->ScrollRectToVisible(selected_view->bounds()); |
| 477 } | 484 } |
| 478 | 485 |
| 479 std::unique_ptr<std::set<std::string>> | 486 std::unique_ptr<std::set<std::string>> |
| 480 NetworkListView::UpdateNetworkListEntries() { | 487 NetworkListView::UpdateNetworkListEntries() { |
| 481 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 488 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 482 | 489 |
| 490 // Keep an index where the next child should be inserted. | |
| 491 int index = 0; | |
| 492 | |
| 493 bool show_connection_warning = | |
| 494 !!NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType( | |
| 495 NetworkTypePattern::VPN()); | |
| 496 | |
| 497 NetworkingConfigDelegate* networking_config_delegate = | |
| 498 Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate(); | |
| 499 if (networking_config_delegate) { | |
| 500 show_connection_warning = | |
| 501 show_connection_warning || | |
| 502 networking_config_delegate->HasDefaultNetworkProxyConfigured(); | |
| 503 } | |
| 504 | |
| 505 if (show_connection_warning) { | |
| 506 if (!connection_warning_) { | |
|
stevenjb
2017/04/20 23:44:55
Move this code to a helper:
connection_warning_ =
sammiequon
2017/04/21 00:05:32
Done.
| |
| 507 // Set up layout and apply sticky row property. | |
| 508 connection_warning_ = TrayPopupUtils::CreateDefaultRowView(); | |
| 509 TrayPopupUtils::ConfigureAsStickyHeader(connection_warning_); | |
| 510 connection_warning_->set_background( | |
| 511 views::Background::CreateSolidBackground(kHeaderBackgroundColor)); | |
| 512 | |
| 513 // Set 'info' icon on left side. | |
| 514 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView(); | |
| 515 image_view->SetImage( | |
| 516 gfx::CreateVectorIcon(kSystemMenuInfoIcon, kMenuIconColor)); | |
| 517 image_view->set_background( | |
| 518 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); | |
| 519 connection_warning_->AddView(TriView::Container::START, image_view); | |
| 520 | |
| 521 // Set message label in middle of row. | |
| 522 views::Label* label = TrayPopupUtils::CreateDefaultLabel(); | |
| 523 label->SetText(l10n_util::GetStringUTF16( | |
| 524 IDS_ASH_STATUS_TRAY_NETWORK_MONITORED_WARNING)); | |
| 525 label->set_background( | |
| 526 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT)); | |
| 527 TrayPopupItemStyle style( | |
| 528 TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL); | |
| 529 style.SetupLabel(label); | |
| 530 connection_warning_->AddView(TriView::Container::CENTER, label); | |
| 531 | |
| 532 // Nothing to the right of the text. | |
| 533 connection_warning_->SetContainerVisible(TriView::Container::END, false); | |
| 534 } | |
| 535 PlaceViewAtIndex(connection_warning_, index++); | |
| 536 } | |
| 537 | |
| 483 // First add high-priority networks (not Wi-Fi nor cellular). | 538 // First add high-priority networks (not Wi-Fi nor cellular). |
| 484 std::unique_ptr<std::set<std::string>> new_guids = | 539 std::unique_ptr<std::set<std::string>> new_guids = |
| 485 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, 0); | 540 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); |
| 486 | 541 index += new_guids->size(); |
| 487 // Keep an index where the next child should be inserted. | |
| 488 int index = new_guids->size(); | |
| 489 | 542 |
| 490 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); | 543 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); |
| 491 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { | 544 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { |
| 492 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { | 545 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { |
| 493 index = UpdateSectionHeaderRow( | 546 index = UpdateSectionHeaderRow( |
| 494 NetworkTypePattern::Cellular(), | 547 NetworkTypePattern::Cellular(), |
| 495 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, | 548 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, |
| 496 &cellular_header_view_, &cellular_separator_view_); | 549 &cellular_header_view_, &cellular_separator_view_); |
| 497 } | 550 } |
| 498 | 551 |
| (...skipping 175 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 674 if (found == last_network_info_map_.end()) { | 727 if (found == last_network_info_map_.end()) { |
| 675 // If we cannot find |info| in |last_network_info_map_|, just return true | 728 // If we cannot find |info| in |last_network_info_map_|, just return true |
| 676 // since this is a new network so we have nothing to compare. | 729 // since this is a new network so we have nothing to compare. |
| 677 return true; | 730 return true; |
| 678 } else { | 731 } else { |
| 679 return *found->second != info; | 732 return *found->second != info; |
| 680 } | 733 } |
| 681 } | 734 } |
| 682 | 735 |
| 683 } // namespace ash | 736 } // namespace ash |
| OLD | NEW |