| 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/metrics/user_metrics_recorder.h" | 7 #include "ash/metrics/user_metrics_recorder.h" |
| 8 #include "ash/shell.h" | 8 #include "ash/shell.h" |
| 9 #include "ash/system/chromeos/network/network_icon_animation.h" |
| 9 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| 10 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 11 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
| 12 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
| 13 #include "ash/system/tray/tray_item_more.h" | 14 #include "ash/system/tray/tray_item_more.h" |
| 14 #include "ash/system/tray/tray_popup_label_button.h" | 15 #include "ash/system/tray/tray_popup_label_button.h" |
| 15 #include "chromeos/network/network_state.h" | 16 #include "chromeos/network/network_state.h" |
| 16 #include "chromeos/network/network_state_handler.h" | 17 #include "chromeos/network/network_state_handler.h" |
| 17 #include "grit/ash_strings.h" | 18 #include "grit/ash_strings.h" |
| 18 #include "third_party/cros_system_api/dbus/service_constants.h" | 19 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 19 #include "ui/base/l10n/l10n_util.h" | 20 #include "ui/base/l10n/l10n_util.h" |
| 20 #include "ui/base/resource/resource_bundle.h" | 21 #include "ui/base/resource/resource_bundle.h" |
| 21 #include "ui/chromeos/network/network_icon_animation.h" | |
| 22 | 22 |
| 23 using chromeos::NetworkHandler; | 23 using chromeos::NetworkHandler; |
| 24 using chromeos::NetworkState; | 24 using chromeos::NetworkState; |
| 25 using chromeos::NetworkStateHandler; | 25 using chromeos::NetworkStateHandler; |
| 26 using chromeos::NetworkTypePattern; | 26 using chromeos::NetworkTypePattern; |
| 27 | 27 |
| 28 namespace ash { | 28 namespace ash { |
| 29 namespace tray { | 29 namespace tray { |
| 30 | 30 |
| 31 class VpnDefaultView : public TrayItemMore, | 31 class VpnDefaultView : public TrayItemMore, |
| 32 public ui::network_icon::AnimationObserver { | 32 public network_icon::AnimationObserver { |
| 33 public: | 33 public: |
| 34 VpnDefaultView(SystemTrayItem* owner, bool show_more) | 34 VpnDefaultView(SystemTrayItem* owner, bool show_more) |
| 35 : TrayItemMore(owner, show_more) { | 35 : TrayItemMore(owner, show_more) { |
| 36 Update(); | 36 Update(); |
| 37 } | 37 } |
| 38 | 38 |
| 39 virtual ~VpnDefaultView() { | 39 virtual ~VpnDefaultView() { |
| 40 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 40 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 41 } | 41 } |
| 42 | 42 |
| 43 static bool ShouldShow() { | 43 static bool ShouldShow() { |
| 44 // Do not show VPN line in uber tray bubble if VPN is not configured. | 44 // Do not show VPN line in uber tray bubble if VPN is not configured. |
| 45 NetworkStateHandler* handler = | 45 NetworkStateHandler* handler = |
| 46 NetworkHandler::Get()->network_state_handler(); | 46 NetworkHandler::Get()->network_state_handler(); |
| 47 const NetworkState* vpn = | 47 const NetworkState* vpn = |
| 48 handler->FirstNetworkByType(NetworkTypePattern::VPN()); | 48 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 49 return vpn != NULL; | 49 return vpn != NULL; |
| 50 } | 50 } |
| 51 | 51 |
| 52 void Update() { | 52 void Update() { |
| 53 gfx::ImageSkia image; | 53 gfx::ImageSkia image; |
| 54 base::string16 label; | 54 base::string16 label; |
| 55 bool animating = false; | 55 bool animating = false; |
| 56 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); | 56 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); |
| 57 if (animating) | 57 if (animating) |
| 58 ui::network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 58 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 59 else | 59 else |
| 60 ui::network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver( | 60 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 61 this); | |
| 62 SetImage(&image); | 61 SetImage(&image); |
| 63 SetLabel(label); | 62 SetLabel(label); |
| 64 SetAccessibleName(label); | 63 SetAccessibleName(label); |
| 65 } | 64 } |
| 66 | 65 |
| 67 // ui::network_icon::AnimationObserver | 66 // network_icon::AnimationObserver |
| 68 virtual void NetworkIconChanged() OVERRIDE { | 67 virtual void NetworkIconChanged() OVERRIDE { |
| 69 Update(); | 68 Update(); |
| 70 } | 69 } |
| 71 | 70 |
| 72 private: | 71 private: |
| 73 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, | 72 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, |
| 74 base::string16* label, | 73 base::string16* label, |
| 75 bool* animating) { | 74 bool* animating) { |
| 76 NetworkStateHandler* handler = | 75 NetworkStateHandler* handler = |
| 77 NetworkHandler::Get()->network_state_handler(); | 76 NetworkHandler::Get()->network_state_handler(); |
| 78 const NetworkState* vpn = | 77 const NetworkState* vpn = |
| 79 handler->FirstNetworkByType(NetworkTypePattern::VPN()); | 78 handler->FirstNetworkByType(NetworkTypePattern::VPN()); |
| 80 if (!vpn || (vpn->connection_state() == shill::kStateIdle)) { | 79 if (!vpn || (vpn->connection_state() == shill::kStateIdle)) { |
| 81 *image = ui::network_icon::GetImageForDisconnectedNetwork( | 80 *image = network_icon::GetImageForDisconnectedNetwork( |
| 82 ui::network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN); | 81 network_icon::ICON_TYPE_DEFAULT_VIEW, shill::kTypeVPN); |
| 83 if (label) { | 82 if (label) { |
| 84 *label = l10n_util::GetStringUTF16( | 83 *label = l10n_util::GetStringUTF16( |
| 85 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); | 84 IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); |
| 86 } | 85 } |
| 87 *animating = false; | 86 *animating = false; |
| 88 return; | 87 return; |
| 89 } | 88 } |
| 90 *animating = vpn->IsConnectingState(); | 89 *animating = vpn->IsConnectingState(); |
| 91 *image = ui::network_icon::GetImageForNetwork( | 90 *image = network_icon::GetImageForNetwork( |
| 92 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); | 91 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 93 if (label) { | 92 if (label) { |
| 94 *label = ui::network_icon::GetLabelForNetwork( | 93 *label = network_icon::GetLabelForNetwork( |
| 95 vpn, ui::network_icon::ICON_TYPE_DEFAULT_VIEW); | 94 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 96 } | 95 } |
| 97 } | 96 } |
| 98 | 97 |
| 99 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); | 98 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); |
| 100 }; | 99 }; |
| 101 | 100 |
| 102 } // namespace tray | 101 } // namespace tray |
| 103 | 102 |
| 104 TrayVPN::TrayVPN(SystemTray* system_tray) | 103 TrayVPN::TrayVPN(SystemTray* system_tray) |
| 105 : SystemTrayItem(system_tray), | 104 : SystemTrayItem(system_tray), |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 168 detailed_->ManagerChanged(); | 167 detailed_->ManagerChanged(); |
| 169 } | 168 } |
| 170 } | 169 } |
| 171 | 170 |
| 172 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { | 171 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { |
| 173 if (detailed_) | 172 if (detailed_) |
| 174 detailed_->NetworkServiceChanged(network); | 173 detailed_->NetworkServiceChanged(network); |
| 175 } | 174 } |
| 176 | 175 |
| 177 } // namespace ash | 176 } // namespace ash |
| OLD | NEW |