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

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 3 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/strings/grit/ash_strings.h" 9 #include "ash/strings/grit/ash_strings.h"
10 #include "ash/system/network/network_icon.h" 10 #include "ash/system/network/network_icon.h"
11 #include "ash/system/network/network_icon_animation.h" 11 #include "ash/system/network/network_icon_animation.h"
12 #include "ash/system/network/network_list_delegate.h" 12 #include "ash/system/network/network_list_delegate.h"
13 #include "ash/system/tray/system_menu_button.h" 13 #include "ash/system/tray/system_menu_button.h"
14 #include "ash/system/tray/tray_constants.h" 14 #include "ash/system/tray/tray_constants.h"
15 #include "ash/system/tray/tray_popup_item_style.h" 15 #include "ash/system/tray/tray_popup_item_style.h"
16 #include "ash/system/tray/tray_popup_utils.h" 16 #include "ash/system/tray/tray_popup_utils.h"
17 #include "ash/system/tray/tri_view.h"
17 #include "base/memory/ptr_util.h" 18 #include "base/memory/ptr_util.h"
18 #include "chromeos/dbus/dbus_thread_manager.h" 19 #include "chromeos/dbus/dbus_thread_manager.h"
19 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" 20 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
20 #include "chromeos/dbus/power_manager_client.h" 21 #include "chromeos/dbus/power_manager_client.h"
21 #include "chromeos/login/login_state.h" 22 #include "chromeos/login/login_state.h"
22 #include "chromeos/network/managed_network_configuration_handler.h" 23 #include "chromeos/network/managed_network_configuration_handler.h"
23 #include "chromeos/network/network_state.h" 24 #include "chromeos/network/network_state.h"
24 #include "chromeos/network/network_state_handler.h" 25 #include "chromeos/network/network_state_handler.h"
25 #include "chromeos/network/network_state_handler_observer.h" 26 #include "chromeos/network/network_state_handler_observer.h"
27 #include "chromeos/network/proxy/ui_proxy_config_service.h"
26 #include "components/device_event_log/device_event_log.h" 28 #include "components/device_event_log/device_event_log.h"
27 #include "ui/base/l10n/l10n_util.h" 29 #include "ui/base/l10n/l10n_util.h"
28 #include "ui/base/resource/resource_bundle.h" 30 #include "ui/base/resource/resource_bundle.h"
29 #include "ui/gfx/color_palette.h" 31 #include "ui/gfx/color_palette.h"
30 #include "ui/gfx/font.h" 32 #include "ui/gfx/font.h"
31 #include "ui/gfx/paint_vector_icon.h" 33 #include "ui/gfx/paint_vector_icon.h"
34 #include "ui/views/background.h"
32 #include "ui/views/controls/button/toggle_button.h" 35 #include "ui/views/controls/button/toggle_button.h"
36 #include "ui/views/controls/image_view.h"
33 #include "ui/views/controls/label.h" 37 #include "ui/views/controls/label.h"
34 #include "ui/views/controls/separator.h" 38 #include "ui/views/controls/separator.h"
35 #include "ui/views/layout/box_layout.h" 39 #include "ui/views/layout/box_layout.h"
36 #include "ui/views/layout/fill_layout.h" 40 #include "ui/views/layout/fill_layout.h"
37 #include "ui/views/painter.h" 41 #include "ui/views/painter.h"
38 #include "ui/views/view.h" 42 #include "ui/views/view.h"
39 43
40 using chromeos::LoginState; 44 using chromeos::LoginState;
41 using chromeos::NetworkHandler; 45 using chromeos::NetworkHandler;
42 using chromeos::NetworkStateHandler; 46 using chromeos::NetworkStateHandler;
(...skipping 239 matching lines...) Expand 10 before | Expand all | Expand 10 after
282 NetworkListView::NetworkListView(NetworkListDelegate* delegate) 286 NetworkListView::NetworkListView(NetworkListDelegate* delegate)
283 : needs_relayout_(false), 287 : needs_relayout_(false),
284 delegate_(delegate), 288 delegate_(delegate),
285 no_wifi_networks_view_(nullptr), 289 no_wifi_networks_view_(nullptr),
286 no_cellular_networks_view_(nullptr), 290 no_cellular_networks_view_(nullptr),
287 cellular_header_view_(nullptr), 291 cellular_header_view_(nullptr),
288 tether_header_view_(nullptr), 292 tether_header_view_(nullptr),
289 wifi_header_view_(nullptr), 293 wifi_header_view_(nullptr),
290 cellular_separator_view_(nullptr), 294 cellular_separator_view_(nullptr),
291 tether_separator_view_(nullptr), 295 tether_separator_view_(nullptr),
292 wifi_separator_view_(nullptr) { 296 wifi_separator_view_(nullptr),
297 connection_warning_(nullptr) {
293 CHECK(delegate_); 298 CHECK(delegate_);
294 } 299 }
295 300
296 NetworkListView::~NetworkListView() { 301 NetworkListView::~NetworkListView() {
297 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); 302 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
298 } 303 }
299 304
300 void NetworkListView::Update() { 305 void NetworkListView::Update() {
301 CHECK(container()); 306 CHECK(container());
302 307
(...skipping 170 matching lines...) Expand 10 before | Expand all | Expand 10 after
473 container()->SizeToPreferredSize(); 478 container()->SizeToPreferredSize();
474 delegate_->RelayoutScrollList(); 479 delegate_->RelayoutScrollList();
475 if (selected_view) 480 if (selected_view)
476 container()->ScrollRectToVisible(selected_view->bounds()); 481 container()->ScrollRectToVisible(selected_view->bounds());
477 } 482 }
478 483
479 std::unique_ptr<std::set<std::string>> 484 std::unique_ptr<std::set<std::string>>
480 NetworkListView::UpdateNetworkListEntries() { 485 NetworkListView::UpdateNetworkListEntries() {
481 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); 486 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
482 487
488 // Keep an index where the next child should be inserted.
489 int index = 0;
490
491 bool show_connection_warning =
492 !!NetworkHandler::Get()->network_state_handler()->ConnectedNetworkByType(
493 NetworkTypePattern::VPN());
494 show_connection_warning =
495 show_connection_warning || NetworkHandler::Get()
496 ->ui_proxy_config_service()
497 ->HasDefaultNetworkProxyConfigured();
498
499 if (show_connection_warning) {
500 if (!connection_warning_)
501 connection_warning_ = CreateConnectionWarning();
502 PlaceViewAtIndex(connection_warning_, index++);
503 }
504
483 // First add high-priority networks (not Wi-Fi nor cellular). 505 // First add high-priority networks (not Wi-Fi nor cellular).
484 std::unique_ptr<std::set<std::string>> new_guids = 506 std::unique_ptr<std::set<std::string>> new_guids =
485 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, 0); 507 UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index);
486 508 index += new_guids->size();
487 // Keep an index where the next child should be inserted.
488 int index = new_guids->size();
489 509
490 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); 510 const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
491 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { 511 if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) {
492 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { 512 if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) {
493 index = UpdateSectionHeaderRow( 513 index = UpdateSectionHeaderRow(
494 NetworkTypePattern::Cellular(), 514 NetworkTypePattern::Cellular(),
495 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, 515 handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index,
496 &cellular_header_view_, &cellular_separator_view_); 516 &cellular_header_view_, &cellular_separator_view_);
497 } 517 }
498 518
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after
673 NetworkInfoMap::const_iterator found = last_network_info_map_.find(info.guid); 693 NetworkInfoMap::const_iterator found = last_network_info_map_.find(info.guid);
674 if (found == last_network_info_map_.end()) { 694 if (found == last_network_info_map_.end()) {
675 // If we cannot find |info| in |last_network_info_map_|, just return true 695 // 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. 696 // since this is a new network so we have nothing to compare.
677 return true; 697 return true;
678 } else { 698 } else {
679 return *found->second != info; 699 return *found->second != info;
680 } 700 }
681 } 701 }
682 702
703 TriView* NetworkListView::CreateConnectionWarning() {
704 // Set up layout and apply sticky row property.
705 TriView* connection_warning = TrayPopupUtils::CreateDefaultRowView();
706 TrayPopupUtils::ConfigureAsStickyHeader(connection_warning);
707 connection_warning->set_background(
708 views::Background::CreateSolidBackground(kHeaderBackgroundColor));
709
710 // Set 'info' icon on left side.
711 views::ImageView* image_view = TrayPopupUtils::CreateMainImageView();
712 image_view->SetImage(
713 gfx::CreateVectorIcon(kSystemMenuInfoIcon, kMenuIconColor));
714 image_view->set_background(
715 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
716 connection_warning->AddView(TriView::Container::START, image_view);
717
718 // Set message label in middle of row.
719 views::Label* label = TrayPopupUtils::CreateDefaultLabel();
720 label->SetText(
721 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_MONITORED_WARNING));
722 label->set_background(
723 views::Background::CreateSolidBackground(SK_ColorTRANSPARENT));
724 TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::DETAILED_VIEW_LABEL);
725 style.SetupLabel(label);
726 connection_warning->AddView(TriView::Container::CENTER, label);
727
728 // Nothing to the right of the text.
729 connection_warning->SetContainerVisible(TriView::Container::END, false);
730 return connection_warning;
731 }
732
683 } // namespace ash 733 } // namespace ash
OLDNEW
« no previous file with comments | « ash/system/network/network_list.h ('k') | chrome/browser/ui/webui/chromeos/login/network_state_informer.cc » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698