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/system/chromeos/network/tray_vpn.h" | 5 #include "ash/system/chromeos/network/tray_vpn.h" |
6 | 6 |
7 #include "ash/ash_switches.h" | |
7 #include "ash/shell.h" | 8 #include "ash/shell.h" |
9 #include "ash/system/chromeos/network/network_icon_animation.h" | |
8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" | 10 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" |
11 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | |
9 #include "ash/system/tray/system_tray.h" | 12 #include "ash/system/tray/system_tray.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 13 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/system_tray_notifier.h" | 14 #include "ash/system/tray/system_tray_notifier.h" |
12 #include "ash/system/tray/tray_constants.h" | 15 #include "ash/system/tray/tray_constants.h" |
13 #include "ash/system/tray/tray_item_more.h" | 16 #include "ash/system/tray/tray_item_more.h" |
17 #include "base/command_line.h" | |
18 #include "chromeos/network/network_state.h" | |
19 #include "chromeos/network/network_state_handler.h" | |
14 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
21 #include "third_party/cros_system_api/dbus/service_constants.h" | |
22 #include "ui/base/l10n/l10n_util.h" | |
15 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
16 | 24 |
25 namespace { | |
26 | |
27 bool UseNewNetworkHandlers() { | |
28 return CommandLine::ForCurrentProcess()->HasSwitch( | |
29 ash::switches::kAshEnableNewNetworkStatusArea); | |
30 } | |
31 | |
32 } | |
33 | |
34 using chromeos::NetworkState; | |
35 using chromeos::NetworkStateHandler; | |
36 | |
17 namespace ash { | 37 namespace ash { |
18 namespace internal { | 38 namespace internal { |
19 | 39 |
20 namespace tray { | 40 namespace tray { |
21 | 41 |
22 class VpnDefaultView : public TrayItemMore { | 42 class VpnDefaultView : public TrayItemMore, |
43 public network_icon::AnimationObserver { | |
23 public: | 44 public: |
24 VpnDefaultView(SystemTrayItem* owner, bool show_more) | 45 VpnDefaultView(SystemTrayItem* owner, bool show_more) |
25 : TrayItemMore(owner, show_more) { | 46 : TrayItemMore(owner, show_more) { |
26 Update(); | 47 Update(); |
48 if (UseNewNetworkHandlers()) | |
49 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | |
27 } | 50 } |
28 | 51 |
29 virtual ~VpnDefaultView() {} | 52 virtual ~VpnDefaultView() { |
53 if (UseNewNetworkHandlers()) | |
54 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | |
55 } | |
30 | 56 |
31 static bool ShouldShow() { | 57 static bool ShouldShow() { |
32 // Do not show VPN line in uber tray bubble if VPN is not configured. | 58 // Do not show VPN line in uber tray bubble if VPN is not configured. |
33 std::vector<NetworkIconInfo> list; | 59 if (UseNewNetworkHandlers()) { |
34 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworks(&list); | 60 NetworkStateHandler* handler = NetworkStateHandler::Get(); |
35 return list.size() != 0; | 61 const NetworkState* vpn = handler->FirstNetworkByType( |
62 flimflam::kTypeVPN); | |
63 LOG(ERROR) << "First VPN: " << (vpn ? vpn->name() : std::string("None")); | |
jennyz
2013/03/04 20:02:53
Is this log message supposed to be here for error?
stevenjb
2013/03/04 20:41:32
Oops. Removed.
| |
64 return vpn != NULL; | |
65 } else { | |
66 std::vector<NetworkIconInfo> list; | |
67 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworks(&list); | |
68 return list.size() != 0; | |
69 } | |
36 } | 70 } |
37 | 71 |
38 void Update() { | 72 void Update() { |
39 NetworkIconInfo info; | 73 if (UseNewNetworkHandlers()) { |
40 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworkIcon(&info); | 74 gfx::ImageSkia image; |
41 SetImage(&info.image); | 75 string16 label; |
42 SetLabel(info.description); | 76 GetNetworkStateHandlerImageAndLabel(&image, &label); |
43 SetAccessibleName(info.description); | 77 SetImage(&image); |
78 SetLabel(label); | |
79 SetAccessibleName(label); | |
80 } else { | |
81 NetworkIconInfo info; | |
82 Shell::GetInstance()->system_tray_delegate()-> | |
83 GetVirtualNetworkIcon(&info); | |
84 SetImage(&info.image); | |
85 SetLabel(info.description); | |
86 SetAccessibleName(info.description); | |
87 } | |
88 } | |
89 | |
90 // network_icon::AnimationObserver | |
91 virtual void NetworkIconChanged() OVERRIDE { | |
92 Update(); | |
44 } | 93 } |
45 | 94 |
46 private: | 95 private: |
96 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, | |
97 string16* label) { | |
98 NetworkStateHandler* handler = NetworkStateHandler::Get(); | |
99 const NetworkState* vpn = handler->FirstNetworkByType( | |
100 flimflam::kTypeVPN); | |
101 if (!vpn) { | |
102 *image = network_icon::GetImageForDisconnectedNetwork( | |
103 network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN); | |
104 if (label) { | |
105 *label = l10n_util::GetStringUTF16( | |
106 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); | |
107 } | |
108 return; | |
109 } | |
110 *image = network_icon::GetImageForNetwork( | |
111 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); | |
112 if (label) { | |
113 *label = network_icon::GetLabelForNetwork( | |
114 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); | |
115 } | |
116 } | |
117 | |
47 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); | 118 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); |
48 }; | 119 }; |
49 | 120 |
50 class VpnListDetailedView : public NetworkListDetailedViewBase { | 121 class VpnListDetailedView : public NetworkListDetailedViewBase { |
51 public: | 122 public: |
52 VpnListDetailedView(SystemTrayItem* owner, | 123 VpnListDetailedView(SystemTrayItem* owner, |
53 user::LoginStatus login, | 124 user::LoginStatus login, |
54 int header_string_id) | 125 int header_string_id) |
55 : NetworkListDetailedViewBase(owner, login, header_string_id), | 126 : NetworkListDetailedViewBase(owner, login, header_string_id), |
56 other_vpn_(NULL), | 127 other_vpn_(NULL), |
(...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
144 | 215 |
145 DISALLOW_COPY_AND_ASSIGN(VpnListDetailedView); | 216 DISALLOW_COPY_AND_ASSIGN(VpnListDetailedView); |
146 }; | 217 }; |
147 | 218 |
148 } // namespace tray | 219 } // namespace tray |
149 | 220 |
150 TrayVPN::TrayVPN(SystemTray* system_tray) | 221 TrayVPN::TrayVPN(SystemTray* system_tray) |
151 : SystemTrayItem(system_tray), | 222 : SystemTrayItem(system_tray), |
152 default_(NULL), | 223 default_(NULL), |
153 detailed_(NULL) { | 224 detailed_(NULL) { |
225 if (UseNewNetworkHandlers()) | |
226 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | |
154 Shell::GetInstance()->system_tray_notifier()->AddVpnObserver(this); | 227 Shell::GetInstance()->system_tray_notifier()->AddVpnObserver(this); |
155 } | 228 } |
156 | 229 |
157 TrayVPN::~TrayVPN() { | 230 TrayVPN::~TrayVPN() { |
158 Shell::GetInstance()->system_tray_notifier()->RemoveVpnObserver(this); | 231 Shell::GetInstance()->system_tray_notifier()->RemoveVpnObserver(this); |
159 } | 232 } |
160 | 233 |
161 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { | 234 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { |
162 return NULL; | 235 return NULL; |
163 } | 236 } |
164 | 237 |
165 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { | 238 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { |
166 CHECK(default_ == NULL); | 239 CHECK(default_ == NULL); |
167 if (status == user::LOGGED_IN_NONE) | 240 if (status == user::LOGGED_IN_NONE) |
168 return NULL; | 241 return NULL; |
169 | 242 |
170 if (!tray::VpnDefaultView::ShouldShow()) | 243 if (!tray::VpnDefaultView::ShouldShow()) |
171 return NULL; | 244 return NULL; |
172 | 245 |
173 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); | 246 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); |
174 return default_; | 247 return default_; |
175 } | 248 } |
176 | 249 |
177 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { | 250 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { |
178 CHECK(detailed_ == NULL); | 251 CHECK(detailed_ == NULL); |
179 detailed_ = new tray::VpnListDetailedView( | 252 |
180 this, status, IDS_ASH_STATUS_TRAY_VPN); | 253 if (UseNewNetworkHandlers()) { |
254 detailed_ = new tray::NetworkStateListDetailedView( | |
255 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status); | |
256 } else { | |
257 detailed_ = new tray::VpnListDetailedView( | |
258 this, status, IDS_ASH_STATUS_TRAY_VPN); | |
259 } | |
181 detailed_->Init(); | 260 detailed_->Init(); |
182 return detailed_; | 261 return detailed_; |
183 } | 262 } |
184 | 263 |
185 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { | 264 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { |
186 return NULL; | 265 return NULL; |
187 } | 266 } |
188 | 267 |
189 void TrayVPN::DestroyTrayView() { | 268 void TrayVPN::DestroyTrayView() { |
190 } | 269 } |
(...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
228 const string16& message, | 307 const string16& message, |
229 const std::vector<string16>& links) { | 308 const std::vector<string16>& links) { |
230 } | 309 } |
231 | 310 |
232 void TrayVPN::ClearNetworkMessage(MessageType message_type) { | 311 void TrayVPN::ClearNetworkMessage(MessageType message_type) { |
233 } | 312 } |
234 | 313 |
235 void TrayVPN::OnWillToggleWifi() { | 314 void TrayVPN::OnWillToggleWifi() { |
236 } | 315 } |
237 | 316 |
317 void TrayVPN::NetworkStateChanged(bool list_changed) { | |
318 if (default_) | |
319 default_->Update(); | |
320 if (detailed_) { | |
321 if (list_changed) | |
322 detailed_->NetworkListChanged(); | |
323 else | |
324 detailed_->ManagerChanged(); | |
325 } | |
326 } | |
327 | |
328 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { | |
329 if (detailed_) | |
330 detailed_->NetworkServiceChanged(network); | |
331 } | |
332 | |
238 } // namespace internal | 333 } // namespace internal |
239 } // namespace ash | 334 } // namespace ash |
OLD | NEW |