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

Side by Side Diff: ash/system/network/network_list.cc

Issue 2836453003: tray: Show warning in network tray when VPN or proxy used. (Closed)
Patch Set: Fixed patch set 1 errors. Created 3 years, 8 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
OLDNEW
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
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
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_)
507 connection_warning_ = CreateConnectionWarning();
508 PlaceViewAtIndex(connection_warning_, index++);
509 }
510
483 // First add high-priority networks (not Wi-Fi nor cellular). 511 // First add high-priority networks (not Wi-Fi nor cellular).
484 std::unique_ptr<std::set<std::string>> new_guids = 512 std::unique_ptr<std::set<std::string>> new_guids =
485 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, 0); 513 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index);
486 514 index += new_guids->size();
487 // Keep an index where the next child should be inserted.
488 int index = new_guids->size();
489 515
490 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); 516 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
491 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { 517 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) {
492 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { 518 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) {
493 index = UpdateSectionHeaderRow( 519 index = UpdateSectionHeaderRow(
494 NetworkTypePattern::Cellular(), 520 NetworkTypePattern::Cellular(),
495 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, 521 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index,
496 &cellular_header_view_, &cellular_separator_view_); 522 &cellular_header_view_, &cellular_separator_view_);
497 } 523 }
498 524
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 NetworkInfoMap::const_iterator found = last_network_info_map_.find(info.guid); 699 NetworkInfoMap::const_iterator found = last_network_info_map_.find(info.guid);
674 if (found == last_network_info_map_.end()) { 700 if (found == last_network_info_map_.end()) {
675 // If we cannot find |info| in |last_network_info_map_|, just return true 701 // 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. 702 // since this is a new network so we have nothing to compare.
677 return true; 703 return true;
678 } else { 704 } else {
679 return *found->second != info; 705 return *found->second != info;
680 } 706 }
681 } 707 }
682 708
709 TriView* NetworkListView::CreateConnectionWarning() {
710 // Set up layout and apply sticky row property.
711 TriView* connection_warning = TrayPopupUtils::CreateDefaultRowView();
712 TrayPopupUtils::ConfigureAsStickyHeader(connection_warning);
713 connection_warning->set_background(
714 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
715
716 // Set 'info' icon on left side.
717 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView();
718 image_view->SetImage(
719 gfx::CreateVectorIcon(kSystemMenuInfoIcon, kMenuIconColor));
720 image_view->set_background(
721 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
722 connection_warning->AddView(TriView::Container::START, image_view);
723
724 // Set message label in middle of row.
725 views::Label* label = TrayPopupUtils::CreateDefaultLabel();
726 label->SetText(
727 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_MONITORED_WARNING));
728 label->set_background(
729 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
730 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
731 style.SetupLabel(label);
732 connection_warning->AddView(TriView::Container::CENTER, label);
733
734 // Nothing to the right of the text.
735 connection_warning->SetContainerVisible(TriView::Container::END, false);
736 return connection_warning;
737 }
738
683 } // namespace ash 739 } // namespace ash
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698