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_state_list_detailed_view.h" | 8 #include "ash/common/system/chromeos/network/network_state_list_detailed_view.h" |
9 #include "ash/common/system/chromeos/network/vpn_delegate.h" | 9 #include "ash/common/system/chromeos/network/vpn_delegate.h" |
10 #include "ash/common/system/tray/system_tray.h" | 10 #include "ash/common/system/tray/system_tray.h" |
11 #include "ash/common/system/tray/system_tray_delegate.h" | 11 #include "ash/common/system/tray/system_tray_delegate.h" |
12 #include "ash/common/system/tray/tray_constants.h" | 12 #include "ash/common/system/tray/tray_constants.h" |
13 #include "ash/common/system/tray/tray_item_more.h" | 13 #include "ash/common/system/tray/tray_item_more.h" |
| 14 #include "ash/common/system/tray/tray_popup_item_style.h" |
14 #include "ash/common/system/tray/tray_popup_label_button.h" | 15 #include "ash/common/system/tray/tray_popup_label_button.h" |
15 #include "ash/common/wm_shell.h" | 16 #include "ash/common/wm_shell.h" |
16 #include "chromeos/network/network_state.h" | 17 #include "chromeos/network/network_state.h" |
17 #include "chromeos/network/network_state_handler.h" | 18 #include "chromeos/network/network_state_handler.h" |
18 #include "grit/ash_strings.h" | 19 #include "grit/ash_strings.h" |
19 #include "grit/ui_chromeos_strings.h" | 20 #include "grit/ui_chromeos_strings.h" |
20 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
21 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
22 #include "ui/chromeos/network/network_icon.h" | 23 #include "ui/chromeos/network/network_icon.h" |
23 #include "ui/chromeos/network/network_icon_animation.h" | 24 #include "ui/chromeos/network/network_icon_animation.h" |
24 #include "ui/chromeos/network/network_icon_animation_observer.h" | 25 #include "ui/chromeos/network/network_icon_animation_observer.h" |
25 | 26 |
26 using chromeos::NetworkHandler; | 27 using chromeos::NetworkHandler; |
27 using chromeos::NetworkState; | 28 using chromeos::NetworkState; |
28 using chromeos::NetworkStateHandler; | 29 using chromeos::NetworkStateHandler; |
29 using chromeos::NetworkTypePattern; | 30 using chromeos::NetworkTypePattern; |
30 | 31 |
31 namespace ash { | 32 namespace ash { |
32 namespace tray { | 33 namespace tray { |
33 | 34 |
34 class VpnDefaultView : public TrayItemMore, | 35 class VpnDefaultView : public TrayItemMore, |
35 public ui::network_icon::AnimationObserver { | 36 public ui::network_icon::AnimationObserver { |
36 public: | 37 public: |
37 VpnDefaultView(SystemTrayItem* owner, bool show_more) | 38 VpnDefaultView(SystemTrayItem* owner, bool show_more) |
38 : TrayItemMore(owner, show_more) { | 39 : TrayItemMore(owner, show_more) {} |
39 Update(); | |
40 } | |
41 | 40 |
42 ~VpnDefaultView() override { | 41 ~VpnDefaultView() override { |
43 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 42 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
44 } | 43 } |
45 | 44 |
46 static bool ShouldShow() { | 45 static bool ShouldShow() { |
47 // Show the VPN entry in the ash tray bubble if at least one third-party VPN | 46 // Show the VPN entry in the ash tray bubble if at least one third-party VPN |
48 // provider is installed. | 47 // provider is installed. |
49 if (WmShell::Get() | 48 if (WmShell::Get() |
50 ->system_tray_delegate() | 49 ->system_tray_delegate() |
(...skipping 21 matching lines...) Expand all Loading... |
72 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( | 71 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( |
73 this); | 72 this); |
74 SetImage(image); | 73 SetImage(image); |
75 SetLabel(label); | 74 SetLabel(label); |
76 SetAccessibleName(label); | 75 SetAccessibleName(label); |
77 } | 76 } |
78 | 77 |
79 // ui::network_icon::AnimationObserver | 78 // ui::network_icon::AnimationObserver |
80 void NetworkIconChanged() override { Update(); } | 79 void NetworkIconChanged() override { Update(); } |
81 | 80 |
| 81 protected: |
| 82 // TrayItemMore: |
| 83 std::unique_ptr<TrayPopupItemStyle> CreateStyle() const override { |
| 84 std::unique_ptr<TrayPopupItemStyle> style = TrayItemMore::CreateStyle(); |
| 85 style->set_color_style( |
| 86 !IsVpnEnabled() |
| 87 ? TrayPopupItemStyle::ColorStyle::DISABLED |
| 88 : IsVpnConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE |
| 89 : TrayPopupItemStyle::ColorStyle::INACTIVE); |
| 90 return style; |
| 91 } |
| 92 |
| 93 void UpdateStyle() override { |
| 94 TrayItemMore::UpdateStyle(); |
| 95 Update(); |
| 96 } |
| 97 |
82 private: | 98 private: |
| 99 bool IsVpnEnabled() const { |
| 100 NetworkStateHandler* handler = |
| 101 NetworkHandler::Get()->network_state_handler(); |
| 102 return handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 103 } |
| 104 |
| 105 bool IsVpnConnected() const { |
| 106 NetworkStateHandler* handler = |
| 107 NetworkHandler::Get()->network_state_handler(); |
| 108 const NetworkState* vpn = |
| 109 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 110 return IsVpnEnabled() && |
| 111 (vpn->IsConnectedState() || vpn->IsConnectingState()); |
| 112 } |
| 113 |
83 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, | 114 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, |
84 base::string16* label, | 115 base::string16* label, |
85 bool* animating) { | 116 bool* animating) { |
| 117 // TODO(bruthig): Update the image to use the proper color. See |
| 118 // https://crbug.com/632147. |
86 NetworkStateHandler* handler = | 119 NetworkStateHandler* handler = |
87 NetworkHandler::Get()->network_state_handler(); | 120 NetworkHandler::Get()->network_state_handler(); |
88 const NetworkState* vpn = | 121 const NetworkState* vpn = |
89 handler->FirstNetworkByType(NetworkTypePattern::VPN()); | 122 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
90 *image = ui::network_icon::GetVpnImage(); | 123 *image = ui::network_icon::GetVpnImage(); |
91 if (!vpn || (!vpn->IsConnectedState() && !vpn->IsConnectingState())) { | 124 if (!IsVpnConnected()) { |
92 if (label) { | 125 if (label) { |
93 *label = | 126 *label = |
94 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); | 127 l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); |
95 } | 128 } |
96 *animating = false; | 129 *animating = false; |
97 return; | 130 return; |
98 } | 131 } |
99 *animating = vpn->IsConnectingState(); | 132 *animating = vpn->IsConnectingState(); |
100 if (label) { | 133 if (label) { |
101 *label = ui::network_icon::GetLabelForNetwork( | 134 *label = ui::network_icon::GetLabelForNetwork( |
(...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
166 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {} | 199 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) {} |
167 | 200 |
168 void TrayVPN::NetworkStateChanged() { | 201 void TrayVPN::NetworkStateChanged() { |
169 if (default_) | 202 if (default_) |
170 default_->Update(); | 203 default_->Update(); |
171 if (detailed_) | 204 if (detailed_) |
172 detailed_->Update(); | 205 detailed_->Update(); |
173 } | 206 } |
174 | 207 |
175 } // namespace ash | 208 } // namespace ash |
OLD | NEW |