| OLD | NEW |
| 1 // Copyright (c) 2012 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2012 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/tray_vpn.h" | 5 #include "ash/common/system/chromeos/network/tray_vpn.h" |
| 6 | 6 |
| 7 #include "ash/common/session/session_state_delegate.h" | 7 #include "ash/common/session/session_state_delegate.h" |
| 8 #include "ash/common/system/chromeos/network/network_icon.h" |
| 9 #include "ash/common/system/chromeos/network/network_icon_animation.h" |
| 10 #include "ash/common/system/chromeos/network/network_icon_animation_observer.h" |
| 8 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h" | 11 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h" |
| 9 #include "ash/common/system/chromeos/network/vpn_delegate.h" | 12 #include "ash/common/system/chromeos/network/vpn_delegate.h" |
| 10 #include "ash/common/system/tray/system_tray.h" | 13 #include "ash/common/system/tray/system_tray.h" |
| 11 #include "ash/common/system/tray/system_tray_delegate.h" | 14 #include "ash/common/system/tray/system_tray_delegate.h" |
| 12 #include "ash/common/system/tray/tray_constants.h" | 15 #include "ash/common/system/tray/tray_constants.h" |
| 13 #include "ash/common/system/tray/tray_item_more.h" | 16 #include "ash/common/system/tray/tray_item_more.h" |
| 14 #include "ash/common/system/tray/tray_popup_item_style.h" | 17 #include "ash/common/system/tray/tray_popup_item_style.h" |
| 15 #include "ash/common/system/tray/tray_popup_label_button.h" | 18 #include "ash/common/system/tray/tray_popup_label_button.h" |
| 16 #include "ash/common/wm_shell.h" | 19 #include "ash/common/wm_shell.h" |
| 17 #include "chromeos/network/network_state.h" | 20 #include "chromeos/network/network_state.h" |
| 18 #include "chromeos/network/network_state_handler.h" | 21 #include "chromeos/network/network_state_handler.h" |
| 19 #include "grit/ash_strings.h" | 22 #include "grit/ash_strings.h" |
| 20 #include "grit/ui_chromeos_strings.h" | |
| 21 #include "third_party/cros_system_api/dbus/service_constants.h" | 23 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 22 #include "ui/base/l10n/l10n_util.h" | 24 #include "ui/base/l10n/l10n_util.h" |
| 23 #include "ui/chromeos/network/network_icon.h" | |
| 24 #include "ui/chromeos/network/network_icon_animation.h" | |
| 25 #include "ui/chromeos/network/network_icon_animation_observer.h" | |
| 26 | 25 |
| 27 using chromeos::NetworkHandler; | 26 using chromeos::NetworkHandler; |
| 28 using chromeos::NetworkState; | 27 using chromeos::NetworkState; |
| 29 using chromeos::NetworkStateHandler; | 28 using chromeos::NetworkStateHandler; |
| 30 using chromeos::NetworkTypePattern; | 29 using chromeos::NetworkTypePattern; |
| 31 | 30 |
| 32 namespace ash { | 31 namespace ash { |
| 33 namespace tray { | 32 namespace tray { |
| 34 | 33 |
| 35 class VpnDefaultView : public TrayItemMore, | 34 class VpnDefaultView : public TrayItemMore, |
| 36 public ui::network_icon::AnimationObserver { | 35 public network_icon::AnimationObserver { |
| 37 public: | 36 public: |
| 38 VpnDefaultView(SystemTrayItem* owner, bool show_more) | 37 VpnDefaultView(SystemTrayItem* owner, bool show_more) |
| 39 : TrayItemMore(owner, show_more) {} | 38 : TrayItemMore(owner, show_more) {} |
| 40 | 39 |
| 41 ~VpnDefaultView() override { | 40 ~VpnDefaultView() override { |
| 42 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 41 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 43 } | 42 } |
| 44 | 43 |
| 45 static bool ShouldShow() { | 44 static bool ShouldShow() { |
| 46 VPNDelegate* vpn_delegate = | 45 VPNDelegate* vpn_delegate = |
| 47 WmShell::Get()->system_tray_delegate()->GetVPNDelegate(); | 46 WmShell::Get()->system_tray_delegate()->GetVPNDelegate(); |
| 48 // Tests may not have a VPN delegate. They should not show the VPN entry. | 47 // Tests may not have a VPN delegate. They should not show the VPN entry. |
| 49 if (!vpn_delegate) | 48 if (!vpn_delegate) |
| 50 return false; | 49 return false; |
| 51 | 50 |
| 52 // Show the VPN entry in the ash tray bubble if at least one third-party VPN | 51 // Show the VPN entry in the ash tray bubble if at least one third-party VPN |
| 53 // provider is installed. | 52 // provider is installed. |
| 54 if (vpn_delegate->HaveThirdPartyVPNProviders()) | 53 if (vpn_delegate->HaveThirdPartyVPNProviders()) |
| 55 return true; | 54 return true; |
| 56 | 55 |
| 57 // Also show the VPN entry if at least one VPN network is configured. | 56 // Also show the VPN entry if at least one VPN network is configured. |
| 58 NetworkStateHandler* const handler = | 57 NetworkStateHandler* const handler = |
| 59 NetworkHandler::Get()->network_state_handler(); | 58 NetworkHandler::Get()->network_state_handler(); |
| 60 if (handler->FirstNetworkByType(NetworkTypePattern::VPN())) | 59 if (handler->FirstNetworkByType(NetworkTypePattern::VPN())) |
| 61 return true; | 60 return true; |
| 62 return false; | 61 return false; |
| 63 } | 62 } |
| 64 | 63 |
| 65 void Update() { | 64 void Update() { |
| 66 gfx::ImageSkia image; | 65 gfx::ImageSkia image; |
| 67 base::string16 label; | 66 base::string16 label; |
| 68 bool animating = false; | 67 bool animating = false; |
| 69 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); | 68 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); |
| 70 if (animating) | 69 if (animating) |
| 71 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 70 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 72 else | 71 else |
| 73 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( | 72 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 74 this); | |
| 75 SetImage(image); | 73 SetImage(image); |
| 76 SetLabel(label); | 74 SetLabel(label); |
| 77 SetAccessibleName(label); | 75 SetAccessibleName(label); |
| 78 } | 76 } |
| 79 | 77 |
| 80 // ui::network_icon::AnimationObserver | 78 // network_icon::AnimationObserver |
| 81 void NetworkIconChanged() override { Update(); } | 79 void NetworkIconChanged() override { Update(); } |
| 82 | 80 |
| 83 protected: | 81 protected: |
| 84 // TrayItemMore: | 82 // TrayItemMore: |
| 85 std::unique_ptr<TrayPopupItemStyle> CreateStyle() const override { | 83 std::unique_ptr<TrayPopupItemStyle> CreateStyle() const override { |
| 86 std::unique_ptr<TrayPopupItemStyle> style = TrayItemMore::CreateStyle(); | 84 std::unique_ptr<TrayPopupItemStyle> style = TrayItemMore::CreateStyle(); |
| 87 style->set_color_style( | 85 style->set_color_style( |
| 88 !IsVpnEnabled() | 86 !IsVpnEnabled() |
| 89 ? TrayPopupItemStyle::ColorStyle::DISABLED | 87 ? TrayPopupItemStyle::ColorStyle::DISABLED |
| 90 : IsVpnConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE | 88 : IsVpnConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE |
| (...skipping 24 matching lines...) Expand all Loading... |
| 115 | 113 |
| 116 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, | 114 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, |
| 117 base::string16* label, | 115 base::string16* label, |
| 118 bool* animating) { | 116 bool* animating) { |
| 119 // TODO(bruthig): Update the image to use the proper color. See | 117 // TODO(bruthig): Update the image to use the proper color. See |
| 120 // https://crbug.com/632147. | 118 // https://crbug.com/632147. |
| 121 NetworkStateHandler* handler = | 119 NetworkStateHandler* handler = |
| 122 NetworkHandler::Get()->network_state_handler(); | 120 NetworkHandler::Get()->network_state_handler(); |
| 123 const NetworkState* vpn = | 121 const NetworkState* vpn = |
| 124 handler->FirstNetworkByType(NetworkTypePattern::VPN()); | 122 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 125 *image = ui::network_icon::GetVpnImage(); | 123 *image = network_icon::GetVpnImage(); |
| 126 if (!IsVpnConnected()) { | 124 if (!IsVpnConnected()) { |
| 127 if (label) { | 125 if (label) { |
| 128 *label = | 126 *label = |
| 129 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); | 127 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); |
| 130 } | 128 } |
| 131 *animating = false; | 129 *animating = false; |
| 132 return; | 130 return; |
| 133 } | 131 } |
| 134 *animating = vpn->IsConnectingState(); | 132 *animating = vpn->IsConnectingState(); |
| 135 if (label) { | 133 if (label) { |
| 136 *label = ui::network_icon::GetLabelForNetwork( | 134 *label = network_icon::GetLabelForNetwork( |
| 137 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); | 135 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 138 } | 136 } |
| 139 } | 137 } |
| 140 | 138 |
| 141 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); | 139 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); |
| 142 }; | 140 }; |
| 143 | 141 |
| 144 } // namespace tray | 142 } // namespace tray |
| 145 | 143 |
| 146 TrayVPN::TrayVPN(SystemTray* system_tray) | 144 TrayVPN::TrayVPN(SystemTray* system_tray) |
| 147 : SystemTrayItem(system_tray, UMA_VPN), | 145 : SystemTrayItem(system_tray, UMA_VPN), |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 201 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {} | 199 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {} |
| 202 | 200 |
| 203 void TrayVPN::NetworkStateChanged() { | 201 void TrayVPN::NetworkStateChanged() { |
| 204 if (default_) | 202 if (default_) |
| 205 default_->Update(); | 203 default_->Update(); |
| 206 if (detailed_) | 204 if (detailed_) |
| 207 detailed_->Update(); | 205 detailed_->Update(); |
| 208 } | 206 } |
| 209 | 207 |
| 210 } // namespace ash | 208 } // namespace ash |
| OLD | NEW |