| 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 return vpn != NULL; |
| 64 } else { |
| 65 std::vector<NetworkIconInfo> list; |
| 66 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworks(&list); |
| 67 return list.size() != 0; |
| 68 } |
| 36 } | 69 } |
| 37 | 70 |
| 38 void Update() { | 71 void Update() { |
| 39 NetworkIconInfo info; | 72 if (UseNewNetworkHandlers()) { |
| 40 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworkIcon(&info); | 73 gfx::ImageSkia image; |
| 41 SetImage(&info.image); | 74 string16 label; |
| 42 SetLabel(info.description); | 75 GetNetworkStateHandlerImageAndLabel(&image, &label); |
| 43 SetAccessibleName(info.description); | 76 SetImage(&image); |
| 77 SetLabel(label); |
| 78 SetAccessibleName(label); |
| 79 } else { |
| 80 NetworkIconInfo info; |
| 81 Shell::GetInstance()->system_tray_delegate()-> |
| 82 GetVirtualNetworkIcon(&info); |
| 83 SetImage(&info.image); |
| 84 SetLabel(info.description); |
| 85 SetAccessibleName(info.description); |
| 86 } |
| 87 } |
| 88 |
| 89 // network_icon::AnimationObserver |
| 90 virtual void NetworkIconChanged() OVERRIDE { |
| 91 Update(); |
| 44 } | 92 } |
| 45 | 93 |
| 46 private: | 94 private: |
| 95 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, |
| 96 string16* label) { |
| 97 NetworkStateHandler* handler = NetworkStateHandler::Get(); |
| 98 const NetworkState* vpn = handler->FirstNetworkByType( |
| 99 flimflam::kTypeVPN); |
| 100 if (!vpn) { |
| 101 *image = network_icon::GetImageForDisconnectedNetwork( |
| 102 network_icon::ICON_TYPE_DEFAULT_VIEW, flimflam::kTypeVPN); |
| 103 if (label) { |
| 104 *label = l10n_util::GetStringUTF16( |
| 105 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); |
| 106 } |
| 107 return; |
| 108 } |
| 109 *image = network_icon::GetImageForNetwork( |
| 110 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 111 if (label) { |
| 112 *label = network_icon::GetLabelForNetwork( |
| 113 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 114 } |
| 115 } |
| 116 |
| 47 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); | 117 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); |
| 48 }; | 118 }; |
| 49 | 119 |
| 50 class VpnListDetailedView : public NetworkListDetailedViewBase { | 120 class VpnListDetailedView : public NetworkListDetailedViewBase { |
| 51 public: | 121 public: |
| 52 VpnListDetailedView(SystemTrayItem* owner, | 122 VpnListDetailedView(SystemTrayItem* owner, |
| 53 user::LoginStatus login, | 123 user::LoginStatus login, |
| 54 int header_string_id) | 124 int header_string_id) |
| 55 : NetworkListDetailedViewBase(owner, login, header_string_id), | 125 : NetworkListDetailedViewBase(owner, login, header_string_id), |
| 56 other_vpn_(NULL), | 126 other_vpn_(NULL), |
| (...skipping 87 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 144 | 214 |
| 145 DISALLOW_COPY_AND_ASSIGN(VpnListDetailedView); | 215 DISALLOW_COPY_AND_ASSIGN(VpnListDetailedView); |
| 146 }; | 216 }; |
| 147 | 217 |
| 148 } // namespace tray | 218 } // namespace tray |
| 149 | 219 |
| 150 TrayVPN::TrayVPN(SystemTray* system_tray) | 220 TrayVPN::TrayVPN(SystemTray* system_tray) |
| 151 : SystemTrayItem(system_tray), | 221 : SystemTrayItem(system_tray), |
| 152 default_(NULL), | 222 default_(NULL), |
| 153 detailed_(NULL) { | 223 detailed_(NULL) { |
| 224 if (UseNewNetworkHandlers()) |
| 225 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 154 Shell::GetInstance()->system_tray_notifier()->AddVpnObserver(this); | 226 Shell::GetInstance()->system_tray_notifier()->AddVpnObserver(this); |
| 155 } | 227 } |
| 156 | 228 |
| 157 TrayVPN::~TrayVPN() { | 229 TrayVPN::~TrayVPN() { |
| 158 Shell::GetInstance()->system_tray_notifier()->RemoveVpnObserver(this); | 230 Shell::GetInstance()->system_tray_notifier()->RemoveVpnObserver(this); |
| 159 } | 231 } |
| 160 | 232 |
| 161 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { | 233 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { |
| 162 return NULL; | 234 return NULL; |
| 163 } | 235 } |
| 164 | 236 |
| 165 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { | 237 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { |
| 166 CHECK(default_ == NULL); | 238 CHECK(default_ == NULL); |
| 167 if (status == user::LOGGED_IN_NONE) | 239 if (status == user::LOGGED_IN_NONE) |
| 168 return NULL; | 240 return NULL; |
| 169 | 241 |
| 170 if (!tray::VpnDefaultView::ShouldShow()) | 242 if (!tray::VpnDefaultView::ShouldShow()) |
| 171 return NULL; | 243 return NULL; |
| 172 | 244 |
| 173 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); | 245 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); |
| 174 return default_; | 246 return default_; |
| 175 } | 247 } |
| 176 | 248 |
| 177 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { | 249 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { |
| 178 CHECK(detailed_ == NULL); | 250 CHECK(detailed_ == NULL); |
| 179 detailed_ = new tray::VpnListDetailedView( | 251 |
| 180 this, status, IDS_ASH_STATUS_TRAY_VPN); | 252 if (UseNewNetworkHandlers()) { |
| 253 detailed_ = new tray::NetworkStateListDetailedView( |
| 254 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status); |
| 255 } else { |
| 256 detailed_ = new tray::VpnListDetailedView( |
| 257 this, status, IDS_ASH_STATUS_TRAY_VPN); |
| 258 } |
| 181 detailed_->Init(); | 259 detailed_->Init(); |
| 182 return detailed_; | 260 return detailed_; |
| 183 } | 261 } |
| 184 | 262 |
| 185 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { | 263 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { |
| 186 return NULL; | 264 return NULL; |
| 187 } | 265 } |
| 188 | 266 |
| 189 void TrayVPN::DestroyTrayView() { | 267 void TrayVPN::DestroyTrayView() { |
| 190 } | 268 } |
| (...skipping 37 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 228 const string16& message, | 306 const string16& message, |
| 229 const std::vector<string16>& links) { | 307 const std::vector<string16>& links) { |
| 230 } | 308 } |
| 231 | 309 |
| 232 void TrayVPN::ClearNetworkMessage(MessageType message_type) { | 310 void TrayVPN::ClearNetworkMessage(MessageType message_type) { |
| 233 } | 311 } |
| 234 | 312 |
| 235 void TrayVPN::OnWillToggleWifi() { | 313 void TrayVPN::OnWillToggleWifi() { |
| 236 } | 314 } |
| 237 | 315 |
| 316 void TrayVPN::NetworkStateChanged(bool list_changed) { |
| 317 if (default_) |
| 318 default_->Update(); |
| 319 if (detailed_) { |
| 320 if (list_changed) |
| 321 detailed_->NetworkListChanged(); |
| 322 else |
| 323 detailed_->ManagerChanged(); |
| 324 } |
| 325 } |
| 326 |
| 327 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { |
| 328 if (detailed_) |
| 329 detailed_->NetworkServiceChanged(network); |
| 330 } |
| 331 |
| 238 } // namespace internal | 332 } // namespace internal |
| 239 } // namespace ash | 333 } // namespace ash |
| OLD | NEW |