Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright 2015 The Chromium Authors. All rights reserved. | 1 // Copyright 2015 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/common/system/chromeos/network/vpn_list_view.h" | 5 #include "ash/common/system/chromeos/network/vpn_list_view.h" |
| 6 | 6 |
| 7 #include <memory> | 7 #include <memory> |
| 8 #include <utility> | 8 #include <utility> |
| 9 #include <vector> | 9 #include <vector> |
| 10 | 10 |
| 11 #include "ash/common/ash_view_ids.h" | 11 #include "ash/common/ash_view_ids.h" |
| 12 #include "ash/common/material_design/material_design_controller.h" | 12 #include "ash/common/material_design/material_design_controller.h" |
| 13 #include "ash/common/system/chromeos/network/network_icon.h" | 13 #include "ash/common/system/chromeos/network/network_icon.h" |
| 14 #include "ash/common/system/chromeos/network/network_icon_animation.h" | 14 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" | 15 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| 16 #include "ash/common/system/chromeos/network/network_list_delegate.h" | 16 #include "ash/common/system/chromeos/network/network_list_delegate.h" |
| 17 #include "ash/common/system/chromeos/network/vpn_list.h" | 17 #include "ash/common/system/chromeos/network/vpn_list.h" |
| 18 #include "ash/common/system/tray/hover_highlight_view.h" | 18 #include "ash/common/system/tray/hover_highlight_view.h" |
| 19 #include "ash/common/system/tray/system_menu_button.h" | 19 #include "ash/common/system/tray/system_menu_button.h" |
| 20 #include "ash/common/system/tray/system_tray_controller.h" | 20 #include "ash/common/system/tray/system_tray_controller.h" |
| 21 #include "ash/common/system/tray/throbber_view.h" | 21 #include "ash/common/system/tray/throbber_view.h" |
| 22 #include "ash/common/system/tray/tray_constants.h" | 22 #include "ash/common/system/tray/tray_constants.h" |
| 23 #include "ash/common/system/tray/tray_popup_label_button.h" | |
| 24 #include "ash/common/system/tray/tray_popup_utils.h" | 23 #include "ash/common/system/tray/tray_popup_utils.h" |
| 25 #include "ash/common/system/tray/tri_view.h" | 24 #include "ash/common/system/tray/tri_view.h" |
| 26 #include "ash/common/wm_shell.h" | 25 #include "ash/common/wm_shell.h" |
| 27 #include "ash/resources/vector_icons/vector_icons.h" | 26 #include "ash/resources/vector_icons/vector_icons.h" |
| 28 #include "base/bind.h" | 27 #include "base/bind.h" |
| 29 #include "base/bind_helpers.h" | 28 #include "base/bind_helpers.h" |
| 30 #include "base/logging.h" | 29 #include "base/logging.h" |
| 31 #include "base/strings/utf_string_conversions.h" | 30 #include "base/strings/utf_string_conversions.h" |
| 32 #include "base/values.h" | 31 #include "base/values.h" |
| 33 #include "chromeos/network/network_connection_handler.h" | 32 #include "chromeos/network/network_connection_handler.h" |
| 34 #include "chromeos/network/network_handler.h" | 33 #include "chromeos/network/network_handler.h" |
| 35 #include "chromeos/network/network_state.h" | 34 #include "chromeos/network/network_state.h" |
| 36 #include "chromeos/network/network_type_pattern.h" | 35 #include "chromeos/network/network_type_pattern.h" |
| 37 #include "grit/ash_strings.h" | 36 #include "grit/ash_strings.h" |
| 38 #include "third_party/cros_system_api/dbus/service_constants.h" | 37 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 39 #include "ui/base/l10n/l10n_util.h" | 38 #include "ui/base/l10n/l10n_util.h" |
| 40 #include "ui/base/resource/resource_bundle.h" | 39 #include "ui/base/resource/resource_bundle.h" |
| 41 #include "ui/gfx/geometry/rect.h" | 40 #include "ui/gfx/geometry/rect.h" |
| 42 #include "ui/gfx/image/image_skia.h" | 41 #include "ui/gfx/image/image_skia.h" |
| 43 #include "ui/gfx/paint_vector_icon.h" | 42 #include "ui/gfx/paint_vector_icon.h" |
| 44 #include "ui/gfx/text_constants.h" | 43 #include "ui/gfx/text_constants.h" |
| 45 #include "ui/views/border.h" | 44 #include "ui/views/border.h" |
| 46 #include "ui/views/controls/button/button.h" | 45 #include "ui/views/controls/button/button.h" |
| 46 #include "ui/views/controls/button/label_button.h" | |
| 47 #include "ui/views/controls/label.h" | 47 #include "ui/views/controls/label.h" |
| 48 #include "ui/views/controls/separator.h" | 48 #include "ui/views/controls/separator.h" |
| 49 #include "ui/views/layout/box_layout.h" | 49 #include "ui/views/layout/box_layout.h" |
| 50 #include "ui/views/layout/fill_layout.h" | 50 #include "ui/views/layout/fill_layout.h" |
| 51 #include "ui/views/view.h" | 51 #include "ui/views/view.h" |
| 52 | 52 |
| 53 namespace ash { | 53 namespace ash { |
| 54 | 54 |
| 55 namespace { | 55 namespace { |
| 56 | 56 |
| 57 bool UseMd() { | 57 bool UseMd() { |
| 58 return MaterialDesignController::IsSystemTrayMenuMaterial(); | 58 return MaterialDesignController::IsSystemTrayMenuMaterial(); |
| 59 } | 59 } |
| 60 | 60 |
| 61 bool IsConnectedOrConnecting(const chromeos::NetworkState* network) { | |
| 62 return network->IsConnectedState() || network->IsConnectingState(); | |
| 63 } | |
| 64 | |
| 65 void IgnoreDisconnectError(const std::string& error_name, | |
| 66 std::unique_ptr<base::DictionaryValue> error_data) {} | |
| 67 | |
| 68 // Indicates whether |network| belongs to this VPN provider. | 61 // Indicates whether |network| belongs to this VPN provider. |
| 69 bool VpnProviderMatchesNetwork(const VPNProvider& provider, | 62 bool VpnProviderMatchesNetwork(const VPNProvider& provider, |
| 70 const chromeos::NetworkState& network) { | 63 const chromeos::NetworkState& network) { |
| 71 if (network.type() != shill::kTypeVPN) | 64 if (network.type() != shill::kTypeVPN) |
| 72 return false; | 65 return false; |
| 73 const bool network_uses_third_party_provider = | 66 const bool network_uses_third_party_provider = |
| 74 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; | 67 network.vpn_provider_type() == shill::kProviderThirdPartyVpn; |
| 75 if (!provider.third_party) | 68 if (!provider.third_party) |
| 76 return !network_uses_third_party_provider; | 69 return !network_uses_third_party_provider; |
| 77 return network_uses_third_party_provider && | 70 return network_uses_third_party_provider && |
| (...skipping 78 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 156 class VPNListNetworkEntry : public VPNListEntryBase, | 149 class VPNListNetworkEntry : public VPNListEntryBase, |
| 157 public network_icon::AnimationObserver { | 150 public network_icon::AnimationObserver { |
| 158 public: | 151 public: |
| 159 VPNListNetworkEntry(VPNListView* parent, | 152 VPNListNetworkEntry(VPNListView* parent, |
| 160 const chromeos::NetworkState* network); | 153 const chromeos::NetworkState* network); |
| 161 ~VPNListNetworkEntry() override; | 154 ~VPNListNetworkEntry() override; |
| 162 | 155 |
| 163 // network_icon::AnimationObserver: | 156 // network_icon::AnimationObserver: |
| 164 void NetworkIconChanged() override; | 157 void NetworkIconChanged() override; |
| 165 | 158 |
| 166 // Overriden from ActionableView. | |
| 167 void ButtonPressed(views::Button* sender, const ui::Event& event) override; | |
| 168 | |
| 169 private: | 159 private: |
| 170 // A disconnect button that will be shown if the network is currently | |
| 171 // connected. Updates the list entry's hover state as the mouse enters/exits | |
| 172 // the button. | |
| 173 class DisconnectButton : public TrayPopupLabelButton { | |
| 174 public: | |
| 175 explicit DisconnectButton(VPNListNetworkEntry* parent); | |
| 176 | |
| 177 private: | |
| 178 // TrayPopupLabelButton: | |
| 179 void OnMouseEntered(const ui::MouseEvent& event) override; | |
| 180 void OnMouseExited(const ui::MouseEvent& event) override; | |
| 181 void OnBoundsChanged(const gfx::Rect& previous_bounds) override; | |
| 182 | |
| 183 VPNListNetworkEntry* parent_; | |
| 184 | |
| 185 DISALLOW_COPY_AND_ASSIGN(DisconnectButton); | |
| 186 }; | |
| 187 | |
| 188 void UpdateFromNetworkState(const chromeos::NetworkState* network); | 160 void UpdateFromNetworkState(const chromeos::NetworkState* network); |
| 189 void SetupConnectedItemMd(const base::string16& text, | 161 void SetupConnectedItemMd(const base::string16& text, |
| 190 const gfx::ImageSkia& image); | 162 const gfx::ImageSkia& image); |
| 191 void SetupConnectingItemMd(const base::string16& text, | 163 void SetupConnectingItemMd(const base::string16& text, |
| 192 const gfx::ImageSkia& image); | 164 const gfx::ImageSkia& image); |
| 193 | 165 |
| 194 const std::string service_path_; | 166 const std::string service_path_; |
| 195 | 167 |
| 196 views::LabelButton* disconnect_button_ = nullptr; | 168 views::LabelButton* disconnect_button_ = nullptr; |
| 197 | 169 |
| (...skipping 15 matching lines...) Expand all Loading... | |
| 213 VPNListNetworkEntry::~VPNListNetworkEntry() { | 185 VPNListNetworkEntry::~VPNListNetworkEntry() { |
| 214 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 186 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 215 } | 187 } |
| 216 | 188 |
| 217 void VPNListNetworkEntry::NetworkIconChanged() { | 189 void VPNListNetworkEntry::NetworkIconChanged() { |
| 218 UpdateFromNetworkState( | 190 UpdateFromNetworkState( |
| 219 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState( | 191 chromeos::NetworkHandler::Get()->network_state_handler()->GetNetworkState( |
| 220 service_path_)); | 192 service_path_)); |
| 221 } | 193 } |
| 222 | 194 |
| 223 void VPNListNetworkEntry::ButtonPressed(views::Button* sender, | |
| 224 const ui::Event& event) { | |
| 225 if (sender != disconnect_button_) { | |
| 226 ActionableView::ButtonPressed(sender, event); | |
| 227 return; | |
| 228 } | |
| 229 | |
| 230 WmShell::Get()->RecordUserMetricsAction( | |
| 231 UMA_STATUS_AREA_VPN_DISCONNECT_CLICKED); | |
| 232 chromeos::NetworkHandler::Get() | |
| 233 ->network_connection_handler() | |
| 234 ->DisconnectNetwork(service_path_, base::Bind(&base::DoNothing), | |
| 235 base::Bind(&IgnoreDisconnectError)); | |
| 236 } | |
| 237 | |
| 238 VPNListNetworkEntry::DisconnectButton::DisconnectButton( | |
| 239 VPNListNetworkEntry* parent) | |
| 240 : TrayPopupLabelButton( | |
| 241 parent, | |
| 242 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)), | |
| 243 parent_(parent) { | |
| 244 DCHECK(!UseMd()); | |
| 245 DCHECK(parent_); | |
| 246 } | |
| 247 | |
| 248 void VPNListNetworkEntry::DisconnectButton::OnMouseEntered( | |
| 249 const ui::MouseEvent& event) { | |
| 250 TrayPopupLabelButton::OnMouseEntered(event); | |
| 251 parent_->SetHoverHighlight(false); | |
| 252 } | |
| 253 | |
| 254 void VPNListNetworkEntry::DisconnectButton::OnMouseExited( | |
| 255 const ui::MouseEvent& event) { | |
| 256 TrayPopupLabelButton::OnMouseExited(event); | |
| 257 if (parent_->IsMouseHovered()) | |
| 258 parent_->SetHoverHighlight(true); | |
| 259 } | |
| 260 | |
| 261 void VPNListNetworkEntry::DisconnectButton::OnBoundsChanged( | |
| 262 const gfx::Rect& previous_bounds) { | |
| 263 TrayPopupLabelButton::OnBoundsChanged(previous_bounds); | |
| 264 if (IsMouseHovered()) { | |
| 265 SetState(STATE_HOVERED); | |
| 266 parent_->SetHoverHighlight(false); | |
| 267 } | |
| 268 } | |
| 269 | |
| 270 void VPNListNetworkEntry::UpdateFromNetworkState( | 195 void VPNListNetworkEntry::UpdateFromNetworkState( |
| 271 const chromeos::NetworkState* network) { | 196 const chromeos::NetworkState* network) { |
| 272 if (network && network->IsConnectingState()) | 197 if (network && network->IsConnectingState()) |
| 273 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 198 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 274 else | 199 else |
| 275 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 200 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 276 | 201 |
| 277 if (!network) { | 202 if (!network) { |
| 278 // This is a transient state where the network has been removed already but | 203 // This is a transient state where the network has been removed already but |
| 279 // the network list in the UI has not been updated yet. | 204 // the network list in the UI has not been updated yet. |
| 280 return; | 205 return; |
| 281 } | 206 } |
| 282 RemoveAllChildViews(true); | 207 RemoveAllChildViews(true); |
| 283 disconnect_button_ = nullptr; | 208 disconnect_button_ = nullptr; |
| 284 | 209 |
| 285 gfx::ImageSkia image = | 210 gfx::ImageSkia image = |
| 286 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); | 211 network_icon::GetImageForNetwork(network, network_icon::ICON_TYPE_LIST); |
| 287 base::string16 label = network_icon::GetLabelForNetwork( | 212 base::string16 label = network_icon::GetLabelForNetwork( |
| 288 network, UseMd() ? network_icon::ICON_TYPE_MENU_LIST | 213 network, UseMd() ? network_icon::ICON_TYPE_MENU_LIST |
| 289 : network_icon::ICON_TYPE_LIST); | 214 : network_icon::ICON_TYPE_LIST); |
| 290 if (UseMd()) { | 215 if (UseMd()) { |
|
tdanderson
2017/02/08 00:39:37
Remove this line and un-indent all lines within bl
Evan Stade
2017/02/08 01:00:20
Done.
| |
| 291 if (network->IsConnectedState()) | 216 if (network->IsConnectedState()) |
| 292 SetupConnectedItemMd(label, image); | 217 SetupConnectedItemMd(label, image); |
| 293 else if (network->IsConnectingState()) | 218 else if (network->IsConnectingState()) |
| 294 SetupConnectingItemMd(label, image); | 219 SetupConnectingItemMd(label, image); |
| 295 else | 220 else |
| 296 AddIconAndLabel(image, label, false); | 221 AddIconAndLabel(image, label, false); |
| 297 | 222 |
| 298 if (network->IsConnectedState()) { | 223 if (network->IsConnectedState()) { |
| 299 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( | 224 disconnect_button_ = TrayPopupUtils::CreateTrayPopupButton( |
| 300 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); | 225 this, l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECT)); |
| 301 tri_view()->AddView(TriView::Container::END, disconnect_button_); | 226 tri_view()->AddView(TriView::Container::END, disconnect_button_); |
| 302 tri_view()->SetContainerVisible(TriView::Container::END, true); | 227 tri_view()->SetContainerVisible(TriView::Container::END, true); |
| 303 tri_view()->SetContainerBorder( | 228 tri_view()->SetContainerBorder( |
| 304 TriView::Container::END, | 229 TriView::Container::END, |
| 305 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); | 230 views::CreateEmptyBorder(0, 0, 0, kTrayPopupButtonEndMargin)); |
| 306 } | 231 } |
| 307 } else { | |
| 308 AddIconAndLabel(image, label, IsConnectedOrConnecting(network)); | |
| 309 if (IsConnectedOrConnecting(network)) { | |
| 310 disconnect_button_ = new DisconnectButton(this); | |
| 311 AddChildView(disconnect_button_); | |
| 312 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 3)); | |
| 313 } else { | |
| 314 SetBorder(views::CreateEmptyBorder(0, kTrayPopupPaddingHorizontal, 0, 0)); | |
| 315 } | |
| 316 // The icon and the disconnect button are always set to their preferred | |
| 317 // size. All remaining space is used for the network name. | |
| 318 views::BoxLayout* layout = new views::BoxLayout( | |
| 319 views::BoxLayout::kHorizontal, 0, 3, kTrayPopupPaddingBetweenItems); | |
| 320 SetLayoutManager(layout); | |
| 321 layout->SetDefaultFlex(0); | |
| 322 layout->SetFlexForView(text_label(), 1); | |
| 323 } | 232 } |
| 324 Layout(); | 233 Layout(); |
| 325 } | 234 } |
| 326 | 235 |
| 327 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. | 236 // TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. |
| 328 void VPNListNetworkEntry::SetupConnectedItemMd(const base::string16& text, | 237 void VPNListNetworkEntry::SetupConnectedItemMd(const base::string16& text, |
| 329 const gfx::ImageSkia& image) { | 238 const gfx::ImageSkia& image) { |
| 330 AddIconAndLabels( | 239 AddIconAndLabels( |
| 331 image, text, | 240 image, text, |
| 332 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); | 241 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED)); |
| (...skipping 192 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 525 } | 434 } |
| 526 } | 435 } |
| 527 | 436 |
| 528 // Add providers without any configured networks, in the order that the | 437 // Add providers without any configured networks, in the order that the |
| 529 // providers were returned by the extensions system. | 438 // providers were returned by the extensions system. |
| 530 for (const VPNProvider& provider : providers) | 439 for (const VPNProvider& provider : providers) |
| 531 AddProviderAndNetworks(provider, networks); | 440 AddProviderAndNetworks(provider, networks); |
| 532 } | 441 } |
| 533 | 442 |
| 534 } // namespace ash | 443 } // namespace ash |
| OLD | NEW |