Chromium Code Reviews| 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/ash_switches.h" |
|
James Cook
2013/05/20 21:06:16
Remove this?
stevenjb
2013/05/20 21:16:50
Done.
| |
| 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_icon_animation.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" | 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| 12 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
| 13 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
| 14 #include "ash/system/tray/system_tray_notifier.h" | 13 #include "ash/system/tray/system_tray_notifier.h" |
| 15 #include "ash/system/tray/tray_constants.h" | 14 #include "ash/system/tray/tray_constants.h" |
| 16 #include "ash/system/tray/tray_item_more.h" | 15 #include "ash/system/tray/tray_item_more.h" |
| 17 #include "ash/system/tray/tray_popup_label_button.h" | 16 #include "ash/system/tray/tray_popup_label_button.h" |
| 18 #include "base/command_line.h" | 17 #include "base/command_line.h" |
|
James Cook
2013/05/20 21:06:16
Remove this. There also might be other files where
stevenjb
2013/05/20 21:16:50
Done.
| |
| 19 #include "chromeos/network/network_state.h" | 18 #include "chromeos/network/network_state.h" |
| 20 #include "chromeos/network/network_state_handler.h" | 19 #include "chromeos/network/network_state_handler.h" |
| 21 #include "grit/ash_strings.h" | 20 #include "grit/ash_strings.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" | 21 #include "third_party/cros_system_api/dbus/service_constants.h" |
| 23 #include "ui/base/l10n/l10n_util.h" | 22 #include "ui/base/l10n/l10n_util.h" |
| 24 #include "ui/base/resource/resource_bundle.h" | 23 #include "ui/base/resource/resource_bundle.h" |
| 25 | 24 |
| 26 using chromeos::NetworkState; | 25 using chromeos::NetworkState; |
| 27 using chromeos::NetworkStateHandler; | 26 using chromeos::NetworkStateHandler; |
| 28 | 27 |
| 29 namespace { | |
| 30 | |
| 31 bool UseNewNetworkHandlers() { | |
| 32 return !CommandLine::ForCurrentProcess()->HasSwitch( | |
| 33 ash::switches::kAshDisableNewNetworkStatusArea) && | |
| 34 NetworkStateHandler::IsInitialized(); | |
| 35 } | |
| 36 | |
| 37 } | |
| 38 | |
| 39 namespace ash { | 28 namespace ash { |
| 40 namespace internal { | 29 namespace internal { |
| 41 | 30 |
| 42 namespace tray { | 31 namespace tray { |
| 43 | 32 |
| 44 class VpnDefaultView : public TrayItemMore, | 33 class VpnDefaultView : public TrayItemMore, |
| 45 public network_icon::AnimationObserver { | 34 public network_icon::AnimationObserver { |
| 46 public: | 35 public: |
| 47 VpnDefaultView(SystemTrayItem* owner, bool show_more) | 36 VpnDefaultView(SystemTrayItem* owner, bool show_more) |
| 48 : TrayItemMore(owner, show_more) { | 37 : TrayItemMore(owner, show_more) { |
| 49 Update(); | 38 Update(); |
| 50 } | 39 } |
| 51 | 40 |
| 52 virtual ~VpnDefaultView() { | 41 virtual ~VpnDefaultView() { |
| 53 if (UseNewNetworkHandlers()) | 42 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 54 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | |
| 55 } | 43 } |
| 56 | 44 |
| 57 static bool ShouldShow() { | 45 static bool ShouldShow() { |
| 58 // Do not show VPN line in uber tray bubble if VPN is not configured. | 46 // Do not show VPN line in uber tray bubble if VPN is not configured. |
| 59 if (UseNewNetworkHandlers()) { | 47 NetworkStateHandler* handler = NetworkStateHandler::Get(); |
| 60 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 48 const NetworkState* vpn = handler->FirstNetworkByType( |
| 61 const NetworkState* vpn = handler->FirstNetworkByType( | 49 flimflam::kTypeVPN); |
| 62 flimflam::kTypeVPN); | 50 return vpn != NULL; |
| 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 } | |
| 69 } | 51 } |
| 70 | 52 |
| 71 void Update() { | 53 void Update() { |
| 72 if (UseNewNetworkHandlers()) { | 54 gfx::ImageSkia image; |
| 73 gfx::ImageSkia image; | 55 base::string16 label; |
| 74 base::string16 label; | 56 bool animating = false; |
| 75 bool animating = false; | 57 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); |
| 76 GetNetworkStateHandlerImageAndLabel(&image, &label, &animating); | 58 if (animating) |
| 77 if (animating) | 59 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 78 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 60 else |
| 79 else | 61 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 80 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 62 SetImage(&image); |
| 81 SetImage(&image); | 63 SetLabel(label); |
| 82 SetLabel(label); | 64 SetAccessibleName(label); |
| 83 SetAccessibleName(label); | |
| 84 } else { | |
| 85 NetworkIconInfo info; | |
| 86 Shell::GetInstance()->system_tray_delegate()-> | |
| 87 GetVirtualNetworkIcon(&info); | |
| 88 SetImage(&info.image); | |
| 89 SetLabel(info.description); | |
| 90 SetAccessibleName(info.description); | |
| 91 } | |
| 92 } | 65 } |
| 93 | 66 |
| 94 // network_icon::AnimationObserver | 67 // network_icon::AnimationObserver |
| 95 virtual void NetworkIconChanged() OVERRIDE { | 68 virtual void NetworkIconChanged() OVERRIDE { |
| 96 Update(); | 69 Update(); |
| 97 } | 70 } |
| 98 | 71 |
| 99 private: | 72 private: |
| 100 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, | 73 void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, |
| 101 base::string16* label, | 74 base::string16* label, |
| (...skipping 16 matching lines...) Expand all Loading... | |
| 118 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); | 91 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 119 if (label) { | 92 if (label) { |
| 120 *label = network_icon::GetLabelForNetwork( | 93 *label = network_icon::GetLabelForNetwork( |
| 121 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); | 94 vpn, network_icon::ICON_TYPE_DEFAULT_VIEW); |
| 122 } | 95 } |
| 123 } | 96 } |
| 124 | 97 |
| 125 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); | 98 DISALLOW_COPY_AND_ASSIGN(VpnDefaultView); |
| 126 }; | 99 }; |
| 127 | 100 |
| 128 class VpnListDetailedView : public NetworkListDetailedViewBase { | |
| 129 public: | |
| 130 VpnListDetailedView(SystemTrayItem* owner, | |
| 131 user::LoginStatus login, | |
| 132 int header_string_id) | |
| 133 : NetworkListDetailedViewBase(owner, login, header_string_id), | |
| 134 other_vpn_(NULL), | |
| 135 no_networks_view_(NULL) { | |
| 136 } | |
| 137 | |
| 138 virtual ~VpnListDetailedView() { | |
| 139 } | |
| 140 | |
| 141 // Overridden from NetworkListDetailedViewBase: | |
| 142 | |
| 143 virtual void AppendHeaderButtons() OVERRIDE { | |
| 144 AppendInfoButtonToHeader(); | |
| 145 } | |
| 146 | |
| 147 virtual void UpdateHeaderButtons() OVERRIDE { | |
| 148 UpdateSettingButton(); | |
| 149 } | |
| 150 | |
| 151 virtual void AppendNetworkEntries() OVERRIDE { | |
| 152 CreateScrollableList(); | |
| 153 } | |
| 154 | |
| 155 virtual void GetAvailableNetworkList( | |
| 156 std::vector<NetworkIconInfo>* list) OVERRIDE{ | |
| 157 Shell::GetInstance()->system_tray_delegate()->GetVirtualNetworks(list); | |
| 158 } | |
| 159 | |
| 160 virtual void UpdateNetworkEntries() OVERRIDE { | |
| 161 RefreshNetworkScrollWithUpdatedNetworkData(); | |
| 162 } | |
| 163 | |
| 164 virtual void AppendCustomButtonsToBottomRow( | |
| 165 views::View* bottom_row) OVERRIDE { | |
| 166 other_vpn_ = new TrayPopupLabelButton( | |
| 167 this, | |
| 168 ui::ResourceBundle::GetSharedInstance().GetLocalizedString( | |
| 169 IDS_ASH_STATUS_TRAY_OTHER_VPN)); | |
| 170 bottom_row->AddChildView(other_vpn_); | |
| 171 } | |
| 172 | |
| 173 virtual void UpdateNetworkExtra() OVERRIDE { | |
| 174 if (login() == user::LOGGED_IN_LOCKED) | |
| 175 return; | |
| 176 } | |
| 177 | |
| 178 virtual void CustomButtonPressed(views::Button* sender, | |
| 179 const ui::Event& event) OVERRIDE { | |
| 180 if (sender == other_vpn_) | |
| 181 ash::Shell::GetInstance()->system_tray_delegate()->ShowOtherVPN(); | |
| 182 else | |
| 183 NOTREACHED(); | |
| 184 } | |
| 185 | |
| 186 virtual bool CustomLinkClickedOn(views::View* sender) OVERRIDE { | |
| 187 return false; | |
| 188 } | |
| 189 | |
| 190 virtual bool UpdateNetworkListEntries( | |
| 191 std::set<std::string>* new_service_paths) OVERRIDE { | |
| 192 ui::ResourceBundle& rb = ui::ResourceBundle::GetSharedInstance(); | |
| 193 bool needs_relayout = false; | |
| 194 | |
| 195 int index = 0; | |
| 196 | |
| 197 for (size_t i = 0; i < network_list().size(); ++i) { | |
| 198 const NetworkIconInfo* info = &network_list()[i]; | |
| 199 if (UpdateNetworkChild(index++, info)) | |
| 200 needs_relayout = true; | |
| 201 new_service_paths->insert(info->service_path); | |
| 202 } | |
| 203 | |
| 204 // We shouldn't be showing this list if there are no VPNs, but it could | |
| 205 // be possible to get here if a VPN were removed (e.g. by a policy) while | |
| 206 // the UI was open. Better to show something than nothing. | |
| 207 if (network_list().empty()) { | |
| 208 if (CreateOrUpdateInfoLabel( | |
| 209 index++, | |
| 210 rb.GetLocalizedString(IDS_ASH_STATUS_TRAY_NETWORK_NO_VPN), | |
| 211 &no_networks_view_)) { | |
| 212 needs_relayout = true; | |
| 213 } | |
| 214 } | |
| 215 | |
| 216 return needs_relayout; | |
| 217 } | |
| 218 | |
| 219 private: | |
| 220 TrayPopupLabelButton* other_vpn_; | |
| 221 views::Label* no_networks_view_; | |
| 222 | |
| 223 DISALLOW_COPY_AND_ASSIGN(VpnListDetailedView); | |
| 224 }; | |
| 225 | |
| 226 } // namespace tray | 101 } // namespace tray |
| 227 | 102 |
| 228 TrayVPN::TrayVPN(SystemTray* system_tray) | 103 TrayVPN::TrayVPN(SystemTray* system_tray) |
| 229 : SystemTrayItem(system_tray), | 104 : SystemTrayItem(system_tray), |
| 230 default_(NULL), | 105 default_(NULL), |
| 231 detailed_(NULL) { | 106 detailed_(NULL) { |
| 232 if (UseNewNetworkHandlers()) | 107 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 233 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | |
| 234 Shell::GetInstance()->system_tray_notifier()->AddVpnObserver(this); | |
| 235 } | 108 } |
| 236 | 109 |
| 237 TrayVPN::~TrayVPN() { | 110 TrayVPN::~TrayVPN() { |
| 238 Shell::GetInstance()->system_tray_notifier()->RemoveVpnObserver(this); | |
| 239 } | 111 } |
| 240 | 112 |
| 241 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { | 113 views::View* TrayVPN::CreateTrayView(user::LoginStatus status) { |
| 242 return NULL; | 114 return NULL; |
| 243 } | 115 } |
| 244 | 116 |
| 245 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { | 117 views::View* TrayVPN::CreateDefaultView(user::LoginStatus status) { |
| 246 CHECK(default_ == NULL); | 118 CHECK(default_ == NULL); |
| 247 if (status == user::LOGGED_IN_NONE) | 119 if (status == user::LOGGED_IN_NONE) |
| 248 return NULL; | 120 return NULL; |
| 249 | 121 |
| 250 if (!tray::VpnDefaultView::ShouldShow()) | 122 if (!tray::VpnDefaultView::ShouldShow()) |
| 251 return NULL; | 123 return NULL; |
| 252 | 124 |
| 253 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); | 125 default_ = new tray::VpnDefaultView(this, status != user::LOGGED_IN_LOCKED); |
| 254 return default_; | 126 return default_; |
| 255 } | 127 } |
| 256 | 128 |
| 257 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { | 129 views::View* TrayVPN::CreateDetailedView(user::LoginStatus status) { |
| 258 CHECK(detailed_ == NULL); | 130 CHECK(detailed_ == NULL); |
| 259 | 131 |
| 260 if (UseNewNetworkHandlers()) { | 132 detailed_ = new tray::NetworkStateListDetailedView( |
| 261 detailed_ = new tray::NetworkStateListDetailedView( | 133 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status); |
| 262 this, tray::NetworkStateListDetailedView::LIST_TYPE_VPN, status); | |
| 263 } else { | |
| 264 detailed_ = new tray::VpnListDetailedView( | |
| 265 this, status, IDS_ASH_STATUS_TRAY_VPN); | |
| 266 } | |
| 267 detailed_->Init(); | 134 detailed_->Init(); |
| 268 return detailed_; | 135 return detailed_; |
| 269 } | 136 } |
| 270 | 137 |
| 271 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { | 138 views::View* TrayVPN::CreateNotificationView(user::LoginStatus status) { |
| 272 return NULL; | 139 return NULL; |
| 273 } | 140 } |
| 274 | 141 |
| 275 void TrayVPN::DestroyTrayView() { | 142 void TrayVPN::DestroyTrayView() { |
| 276 } | 143 } |
| 277 | 144 |
| 278 void TrayVPN::DestroyDefaultView() { | 145 void TrayVPN::DestroyDefaultView() { |
| 279 default_ = NULL; | 146 default_ = NULL; |
| 280 } | 147 } |
| 281 | 148 |
| 282 void TrayVPN::DestroyDetailedView() { | 149 void TrayVPN::DestroyDetailedView() { |
| 283 detailed_ = NULL; | 150 detailed_ = NULL; |
| 284 } | 151 } |
| 285 | 152 |
| 286 void TrayVPN::DestroyNotificationView() { | 153 void TrayVPN::DestroyNotificationView() { |
| 287 } | 154 } |
| 288 | 155 |
| 289 void TrayVPN::UpdateAfterLoginStatusChange(user::LoginStatus status) { | 156 void TrayVPN::UpdateAfterLoginStatusChange(user::LoginStatus status) { |
| 290 } | 157 } |
| 291 | 158 |
| 292 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 159 void TrayVPN::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
| 293 } | 160 } |
| 294 | 161 |
| 295 void TrayVPN::OnNetworkRefresh(const NetworkIconInfo& info) { | |
| 296 if (default_) { | |
| 297 default_->Update(); | |
| 298 } else if (tray::VpnDefaultView::ShouldShow()) { | |
| 299 if (system_tray()->HasSystemBubbleType( | |
| 300 SystemTrayBubble::BUBBLE_TYPE_DEFAULT)) { | |
| 301 // We created the default view without a VPN view, so rebuild it. | |
| 302 system_tray()->ShowDefaultView(BUBBLE_USE_EXISTING); | |
| 303 } | |
| 304 } | |
| 305 | |
| 306 if (detailed_) | |
| 307 detailed_->ManagerChanged(); | |
| 308 } | |
| 309 | |
| 310 void TrayVPN::SetNetworkMessage(NetworkTrayDelegate* delegate, | |
| 311 MessageType message_type, | |
| 312 NetworkType network_type, | |
| 313 const base::string16& title, | |
| 314 const base::string16& message, | |
| 315 const std::vector<base::string16>& links) { | |
| 316 } | |
| 317 | |
| 318 void TrayVPN::ClearNetworkMessage(MessageType message_type) { | |
| 319 } | |
| 320 | |
| 321 void TrayVPN::OnWillToggleWifi() { | |
| 322 } | |
| 323 | |
| 324 void TrayVPN::NetworkStateChanged(bool list_changed) { | 162 void TrayVPN::NetworkStateChanged(bool list_changed) { |
| 325 if (default_) | 163 if (default_) |
| 326 default_->Update(); | 164 default_->Update(); |
| 327 if (detailed_) { | 165 if (detailed_) { |
| 328 if (list_changed) | 166 if (list_changed) |
| 329 detailed_->NetworkListChanged(); | 167 detailed_->NetworkListChanged(); |
| 330 else | 168 else |
| 331 detailed_->ManagerChanged(); | 169 detailed_->ManagerChanged(); |
| 332 } | 170 } |
| 333 } | 171 } |
| 334 | 172 |
| 335 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { | 173 void TrayVPN::NetworkServiceChanged(const chromeos::NetworkState* network) { |
| 336 if (detailed_) | 174 if (detailed_) |
| 337 detailed_->NetworkServiceChanged(network); | 175 detailed_->NetworkServiceChanged(network); |
| 338 } | 176 } |
| 339 | 177 |
| 340 } // namespace internal | 178 } // namespace internal |
| 341 } // namespace ash | 179 } // namespace ash |
| OLD | NEW |