Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2014 The Chromium Authors. All rights reserved. | 1 // Copyright 2014 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 "ui/chromeos/network/network_list.h" | 5 #include "ui/chromeos/network/network_list.h" |
| 6 | 6 |
| 7 #include "chromeos/dbus/dbus_thread_manager.h" | 7 #include "chromeos/dbus/dbus_thread_manager.h" |
| 8 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" | 8 #include "chromeos/dbus/power_manager/power_supply_properties.pb.h" |
| 9 #include "chromeos/dbus/power_manager_client.h" | 9 #include "chromeos/dbus/power_manager_client.h" |
| 10 #include "chromeos/login/login_state.h" | |
| 11 #include "chromeos/network/managed_network_configuration_handler.h" | |
| 10 #include "chromeos/network/network_state.h" | 12 #include "chromeos/network/network_state.h" |
| 11 #include "chromeos/network/network_state_handler.h" | 13 #include "chromeos/network/network_state_handler.h" |
| 12 #include "chromeos/network/network_state_handler_observer.h" | 14 #include "chromeos/network/network_state_handler_observer.h" |
| 13 #include "components/device_event_log/device_event_log.h" | 15 #include "components/device_event_log/device_event_log.h" |
| 14 #include "grit/ui_chromeos_strings.h" | 16 #include "grit/ui_chromeos_strings.h" |
| 17 #include "ui/base/l10n/l10n_util.h" | |
| 15 #include "ui/base/resource/resource_bundle.h" | 18 #include "ui/base/resource/resource_bundle.h" |
| 16 #include "ui/chromeos/network/network_icon.h" | 19 #include "ui/chromeos/network/network_icon.h" |
| 17 #include "ui/chromeos/network/network_icon_animation.h" | 20 #include "ui/chromeos/network/network_icon_animation.h" |
| 18 #include "ui/chromeos/network/network_info.h" | 21 #include "ui/chromeos/network/network_info.h" |
| 19 #include "ui/chromeos/network/network_list_delegate.h" | 22 #include "ui/chromeos/network/network_list_delegate.h" |
| 20 #include "ui/gfx/font.h" | 23 #include "ui/gfx/font.h" |
| 21 #include "ui/views/controls/label.h" | 24 #include "ui/views/controls/label.h" |
| 22 #include "ui/views/view.h" | 25 #include "ui/views/view.h" |
| 23 | 26 |
| 27 using chromeos::LoginState; | |
| 24 using chromeos::NetworkHandler; | 28 using chromeos::NetworkHandler; |
| 25 using chromeos::NetworkStateHandler; | 29 using chromeos::NetworkStateHandler; |
| 30 using chromeos::ManagedNetworkConfigurationHandler; | |
| 26 using chromeos::NetworkTypePattern; | 31 using chromeos::NetworkTypePattern; |
| 27 | 32 |
| 28 namespace ui { | 33 namespace ui { |
| 29 | 34 |
| 35 namespace { | |
| 36 | |
| 37 bool IsProhibitedByPolicy(const chromeos::NetworkState* network) { | |
| 38 ManagedNetworkConfigurationHandler* managed_configuration_handler = | |
| 39 NetworkHandler::Get()->managed_network_configuration_handler(); | |
|
stevenjb
2015/11/23 22:05:53
Move this just before it is used, after the early
stevenjb
2015/11/23 22:05:53
Move this just before it is used, after the early
| |
| 40 if (!NetworkTypePattern::WiFi().MatchesType(network->type())) | |
| 41 return false; | |
| 42 if (!LoginState::IsInitialized() || !LoginState::Get()->IsUserLoggedIn()) | |
| 43 return false; | |
| 44 const base::DictionaryValue* global_network_config = | |
| 45 managed_configuration_handler->GetGlobalConfigFromPolicy( | |
| 46 std::string() /* no username hash, device policy */); | |
| 47 bool policy_prohibites_unmanaged = false; | |
| 48 if (global_network_config) { | |
| 49 global_network_config->GetBooleanWithoutPathExpansion( | |
| 50 ::onc::global_network_config::kAllowOnlyPolicyNetworksToConnect, | |
| 51 &policy_prohibites_unmanaged); | |
| 52 } | |
| 53 if (!policy_prohibites_unmanaged) | |
| 54 return false; | |
| 55 return !managed_configuration_handler->FindPolicyByGuidAndProfile( | |
| 56 network->guid(), network->profile_path()); | |
| 57 } | |
| 58 | |
| 59 } // namespace | |
| 60 | |
| 30 // NetworkListView: | 61 // NetworkListView: |
| 31 | 62 |
| 32 NetworkListView::NetworkListView(NetworkListDelegate* delegate) | 63 NetworkListView::NetworkListView(NetworkListDelegate* delegate) |
| 33 : delegate_(delegate), | 64 : delegate_(delegate), |
| 34 no_wifi_networks_view_(NULL), | 65 no_wifi_networks_view_(NULL), |
| 35 no_cellular_networks_view_(NULL) { | 66 no_cellular_networks_view_(NULL) { |
| 36 CHECK(delegate_); | 67 CHECK(delegate_); |
| 37 } | 68 } |
| 38 | 69 |
| 39 NetworkListView::~NetworkListView() { | 70 NetworkListView::~NetworkListView() { |
| (...skipping 36 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 76 network_list_.push_back(info); | 107 network_list_.push_back(info); |
| 77 } | 108 } |
| 78 } | 109 } |
| 79 | 110 |
| 80 void NetworkListView::UpdateNetworkIcons() { | 111 void NetworkListView::UpdateNetworkIcons() { |
| 81 SCOPED_NET_LOG_IF_SLOW(); | 112 SCOPED_NET_LOG_IF_SLOW(); |
| 82 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); | 113 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 83 | 114 |
| 84 // First, update state for all networks | 115 // First, update state for all networks |
| 85 bool animating = false; | 116 bool animating = false; |
| 117 | |
| 86 for (size_t i = 0; i < network_list_.size(); ++i) { | 118 for (size_t i = 0; i < network_list_.size(); ++i) { |
| 87 NetworkInfo* info = network_list_[i]; | 119 NetworkInfo* info = network_list_[i]; |
| 88 const chromeos::NetworkState* network = | 120 const chromeos::NetworkState* network = |
| 89 handler->GetNetworkState(info->service_path); | 121 handler->GetNetworkState(info->service_path); |
| 90 if (!network) | 122 if (!network) |
| 91 continue; | 123 continue; |
| 124 bool prohibited_by_policy = IsProhibitedByPolicy(network); | |
| 92 info->image = | 125 info->image = |
| 93 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 126 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 94 info->label = | 127 info->label = |
| 95 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST); | 128 network_icon::GetLabelForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 96 info->highlight = | 129 info->highlight = |
| 97 network->IsConnectedState() || network->IsConnectingState(); | 130 network->IsConnectedState() || network->IsConnectingState(); |
| 98 info->disable = | 131 info->disable = |
| 99 network->activation_state() == shill::kActivationStateActivating; | 132 (network->activation_state() == shill::kActivationStateActivating) || |
| 133 prohibited_by_policy; | |
| 134 if (prohibited_by_policy) { | |
| 135 info->tooltip = | |
| 136 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_PROHIBITED); | |
| 137 } | |
| 100 if (!animating && network->IsConnectingState()) | 138 if (!animating && network->IsConnectingState()) |
| 101 animating = true; | 139 animating = true; |
| 102 } | 140 } |
| 103 if (animating) | 141 if (animating) |
| 104 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 142 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 105 else | 143 else |
| 106 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 144 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 107 } | 145 } |
| 108 | 146 |
| 109 void NetworkListView::UpdateNetworkListInternal() { | 147 void NetworkListView::UpdateNetworkListInternal() { |
| (...skipping 167 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 277 needs_relayout = true; | 315 needs_relayout = true; |
| 278 } | 316 } |
| 279 return needs_relayout; | 317 return needs_relayout; |
| 280 } | 318 } |
| 281 | 319 |
| 282 void NetworkListView::NetworkIconChanged() { | 320 void NetworkListView::NetworkIconChanged() { |
| 283 Update(); | 321 Update(); |
| 284 } | 322 } |
| 285 | 323 |
| 286 } // namespace ui | 324 } // namespace ui |
| OLD | NEW |