| 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_network.h" | 5 #include "ash/system/chromeos/network/tray_network.h" |
| 6 | 6 |
| 7 #include "ash/ash_switches.h" | 7 #include "ash/ash_switches.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_icon_animation.h" |
| 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| (...skipping 18 matching lines...) Expand all Loading... |
| 29 #include "ui/base/l10n/l10n_util.h" | 29 #include "ui/base/l10n/l10n_util.h" |
| 30 #include "ui/base/resource/resource_bundle.h" | 30 #include "ui/base/resource/resource_bundle.h" |
| 31 #include "ui/views/controls/image_view.h" | 31 #include "ui/views/controls/image_view.h" |
| 32 #include "ui/views/controls/link.h" | 32 #include "ui/views/controls/link.h" |
| 33 #include "ui/views/controls/link_listener.h" | 33 #include "ui/views/controls/link_listener.h" |
| 34 #include "ui/views/layout/box_layout.h" | 34 #include "ui/views/layout/box_layout.h" |
| 35 #include "ui/views/widget/widget.h" | 35 #include "ui/views/widget/widget.h" |
| 36 | 36 |
| 37 using ash::internal::TrayNetwork; | 37 using ash::internal::TrayNetwork; |
| 38 using ash::NetworkObserver; | 38 using ash::NetworkObserver; |
| 39 using chromeos::NetworkHandler; |
| 39 using chromeos::NetworkState; | 40 using chromeos::NetworkState; |
| 40 using chromeos::NetworkStateHandler; | 41 using chromeos::NetworkStateHandler; |
| 41 | 42 |
| 42 namespace { | 43 namespace { |
| 43 | 44 |
| 44 int GetMessageIcon(NetworkObserver::MessageType message_type, | 45 int GetMessageIcon(NetworkObserver::MessageType message_type, |
| 45 NetworkObserver::NetworkType network_type) { | 46 NetworkObserver::NetworkType network_type) { |
| 46 switch(message_type) { | 47 switch(message_type) { |
| 47 case NetworkObserver::ERROR_CONNECT_FAILED: | 48 case NetworkObserver::ERROR_CONNECT_FAILED: |
| 48 if (NetworkObserver::NETWORK_CELLULAR == network_type) | 49 if (NetworkObserver::NETWORK_CELLULAR == network_type) |
| (...skipping 64 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 113 | 114 |
| 114 virtual ~NetworkTrayView() { | 115 virtual ~NetworkTrayView() { |
| 115 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); | 116 network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); |
| 116 } | 117 } |
| 117 | 118 |
| 118 virtual const char* GetClassName() const OVERRIDE { | 119 virtual const char* GetClassName() const OVERRIDE { |
| 119 return "NetworkTrayView"; | 120 return "NetworkTrayView"; |
| 120 } | 121 } |
| 121 | 122 |
| 122 void UpdateNetworkStateHandlerIcon() { | 123 void UpdateNetworkStateHandlerIcon() { |
| 123 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 124 NetworkStateHandler* handler = |
| 125 NetworkHandler::Get()->network_state_handler(); |
| 124 gfx::ImageSkia image; | 126 gfx::ImageSkia image; |
| 125 base::string16 name; | 127 base::string16 name; |
| 126 bool animating = false; | 128 bool animating = false; |
| 127 network_tray_->GetNetworkStateHandlerImageAndLabel( | 129 network_tray_->GetNetworkStateHandlerImageAndLabel( |
| 128 network_icon::ICON_TYPE_TRAY, &image, &name, &animating); | 130 network_icon::ICON_TYPE_TRAY, &image, &name, &animating); |
| 129 bool show_in_tray = !image.isNull(); | 131 bool show_in_tray = !image.isNull(); |
| 130 UpdateIcon(show_in_tray, image); | 132 UpdateIcon(show_in_tray, image); |
| 131 if (animating) | 133 if (animating) |
| 132 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); | 134 network_icon::NetworkIconAnimation::GetInstance()->AddObserver(this); |
| 133 else | 135 else |
| (...skipping 124 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 258 virtual void NetworkListChanged() OVERRIDE { | 260 virtual void NetworkListChanged() OVERRIDE { |
| 259 Update(); | 261 Update(); |
| 260 } | 262 } |
| 261 | 263 |
| 262 virtual void NetworkServiceChanged( | 264 virtual void NetworkServiceChanged( |
| 263 const chromeos::NetworkState* network) OVERRIDE { | 265 const chromeos::NetworkState* network) OVERRIDE { |
| 264 } | 266 } |
| 265 | 267 |
| 266 private: | 268 private: |
| 267 void Update() { | 269 void Update() { |
| 268 bool wifi_enabled = | 270 bool wifi_enabled = NetworkHandler::Get()->network_state_handler()-> |
| 269 NetworkStateHandler::Get()->IsTechnologyEnabled(flimflam::kTypeWifi); | 271 IsTechnologyEnabled(flimflam::kTypeWifi); |
| 270 const int image_id = wifi_enabled ? | 272 const int image_id = wifi_enabled ? |
| 271 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; | 273 IDR_AURA_UBER_TRAY_WIFI_ENABLED : IDR_AURA_UBER_TRAY_WIFI_DISABLED; |
| 272 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); | 274 ui::ResourceBundle& bundle = ui::ResourceBundle::GetSharedInstance(); |
| 273 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); | 275 image_view_->SetImage(bundle.GetImageNamed(image_id).ToImageSkia()); |
| 274 | 276 |
| 275 const int string_id = wifi_enabled ? | 277 const int string_id = wifi_enabled ? |
| 276 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : | 278 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : |
| 277 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; | 279 IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED; |
| 278 label_view_->SetText(bundle.GetLocalizedString(string_id)); | 280 label_view_->SetText(bundle.GetLocalizedString(string_id)); |
| 279 } | 281 } |
| (...skipping 114 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 394 | 396 |
| 395 TrayNetwork::TrayNetwork(SystemTray* system_tray) | 397 TrayNetwork::TrayNetwork(SystemTray* system_tray) |
| 396 : SystemTrayItem(system_tray), | 398 : SystemTrayItem(system_tray), |
| 397 tray_(NULL), | 399 tray_(NULL), |
| 398 default_(NULL), | 400 default_(NULL), |
| 399 detailed_(NULL), | 401 detailed_(NULL), |
| 400 notification_(NULL), | 402 notification_(NULL), |
| 401 messages_(new tray::NetworkMessages()), | 403 messages_(new tray::NetworkMessages()), |
| 402 request_wifi_view_(false) { | 404 request_wifi_view_(false) { |
| 403 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | 405 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 404 if (NetworkStateHandler::IsInitialized()) | 406 if (NetworkHandler::IsInitialized()) |
| 405 network_state_notifier_.reset(new NetworkStateNotifier()); | 407 network_state_notifier_.reset(new NetworkStateNotifier()); |
| 406 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); | 408 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); |
| 407 } | 409 } |
| 408 | 410 |
| 409 TrayNetwork::~TrayNetwork() { | 411 TrayNetwork::~TrayNetwork() { |
| 410 network_state_notifier_.reset(); | 412 network_state_notifier_.reset(); |
| 411 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); | 413 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); |
| 412 } | 414 } |
| 413 | 415 |
| 414 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 416 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
| 415 CHECK(tray_ == NULL); | 417 CHECK(tray_ == NULL); |
| 416 if (!chromeos::NetworkStateHandler::IsInitialized()) | 418 if (!chromeos::NetworkHandler::IsInitialized()) |
| 417 return NULL; | 419 return NULL; |
| 418 tray_ = new tray::NetworkTrayView(this); | 420 tray_ = new tray::NetworkTrayView(this); |
| 419 return tray_; | 421 return tray_; |
| 420 } | 422 } |
| 421 | 423 |
| 422 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { | 424 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { |
| 423 CHECK(default_ == NULL); | 425 CHECK(default_ == NULL); |
| 424 if (!chromeos::NetworkStateHandler::IsInitialized()) | 426 if (!chromeos::NetworkHandler::IsInitialized()) |
| 425 return NULL; | 427 return NULL; |
| 426 CHECK(tray_ != NULL); | 428 CHECK(tray_ != NULL); |
| 427 default_ = new tray::NetworkDefaultView( | 429 default_ = new tray::NetworkDefaultView( |
| 428 this, status != user::LOGGED_IN_LOCKED); | 430 this, status != user::LOGGED_IN_LOCKED); |
| 429 return default_; | 431 return default_; |
| 430 } | 432 } |
| 431 | 433 |
| 432 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { | 434 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { |
| 433 CHECK(detailed_ == NULL); | 435 CHECK(detailed_ == NULL); |
| 434 if (!chromeos::NetworkStateHandler::IsInitialized()) | 436 if (!chromeos::NetworkHandler::IsInitialized()) |
| 435 return NULL; | 437 return NULL; |
| 436 // Clear any notifications when showing the detailed view. | 438 // Clear any notifications when showing the detailed view. |
| 437 messages_->messages().clear(); | 439 messages_->messages().clear(); |
| 438 HideNotificationView(); | 440 HideNotificationView(); |
| 439 if (request_wifi_view_) { | 441 if (request_wifi_view_) { |
| 440 detailed_ = new tray::NetworkWifiDetailedView(this); | 442 detailed_ = new tray::NetworkWifiDetailedView(this); |
| 441 request_wifi_view_ = false; | 443 request_wifi_view_ = false; |
| 442 } else { | 444 } else { |
| 443 detailed_ = new tray::NetworkStateListDetailedView( | 445 detailed_ = new tray::NetworkStateListDetailedView( |
| 444 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); | 446 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); |
| (...skipping 62 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 507 ShowNotificationView(); | 509 ShowNotificationView(); |
| 508 } | 510 } |
| 509 | 511 |
| 510 void TrayNetwork::RequestToggleWifi() { | 512 void TrayNetwork::RequestToggleWifi() { |
| 511 // This will always be triggered by a user action (e.g. keyboard shortcut) | 513 // This will always be triggered by a user action (e.g. keyboard shortcut) |
| 512 if (!detailed_ || | 514 if (!detailed_ || |
| 513 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { | 515 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { |
| 514 request_wifi_view_ = true; | 516 request_wifi_view_ = true; |
| 515 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 517 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
| 516 } | 518 } |
| 517 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 519 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 518 bool enabled = handler->IsTechnologyEnabled(flimflam::kTypeWifi); | 520 bool enabled = handler->IsTechnologyEnabled(flimflam::kTypeWifi); |
| 519 handler->SetTechnologyEnabled( | 521 handler->SetTechnologyEnabled( |
| 520 flimflam::kTypeWifi, !enabled, | 522 flimflam::kTypeWifi, !enabled, |
| 521 chromeos::network_handler::ErrorCallback()); | 523 chromeos::network_handler::ErrorCallback()); |
| 522 } | 524 } |
| 523 | 525 |
| 524 void TrayNetwork::NetworkStateChanged(bool list_changed) { | 526 void TrayNetwork::NetworkStateChanged(bool list_changed) { |
| 525 if (tray_) | 527 if (tray_) |
| 526 tray_->UpdateNetworkStateHandlerIcon(); | 528 tray_->UpdateNetworkStateHandlerIcon(); |
| 527 if (default_) | 529 if (default_) |
| 528 default_->Update(); | 530 default_->Update(); |
| 529 if (detailed_) { | 531 if (detailed_) { |
| 530 if (list_changed) | 532 if (list_changed) |
| 531 detailed_->NetworkListChanged(); | 533 detailed_->NetworkListChanged(); |
| 532 else | 534 else |
| 533 detailed_->ManagerChanged(); | 535 detailed_->ManagerChanged(); |
| 534 } | 536 } |
| 535 } | 537 } |
| 536 | 538 |
| 537 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { | 539 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { |
| 538 if (detailed_) | 540 if (detailed_) |
| 539 detailed_->NetworkServiceChanged(network); | 541 detailed_->NetworkServiceChanged(network); |
| 540 } | 542 } |
| 541 | 543 |
| 542 void TrayNetwork::GetNetworkStateHandlerImageAndLabel( | 544 void TrayNetwork::GetNetworkStateHandlerImageAndLabel( |
| 543 network_icon::IconType icon_type, | 545 network_icon::IconType icon_type, |
| 544 gfx::ImageSkia* image, | 546 gfx::ImageSkia* image, |
| 545 base::string16* label, | 547 base::string16* label, |
| 546 bool* animating) { | 548 bool* animating) { |
| 547 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 549 NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler(); |
| 548 const NetworkState* connected_network = handler->ConnectedNetworkByType( | 550 const NetworkState* connected_network = handler->ConnectedNetworkByType( |
| 549 NetworkStateHandler::kMatchTypeNonVirtual); | 551 NetworkStateHandler::kMatchTypeNonVirtual); |
| 550 const NetworkState* connecting_network = handler->ConnectingNetworkByType( | 552 const NetworkState* connecting_network = handler->ConnectingNetworkByType( |
| 551 NetworkStateHandler::kMatchTypeWireless); | 553 NetworkStateHandler::kMatchTypeWireless); |
| 552 if (!connecting_network && icon_type == network_icon::ICON_TYPE_TRAY) | 554 if (!connecting_network && icon_type == network_icon::ICON_TYPE_TRAY) |
| 553 connecting_network = handler->ConnectingNetworkByType(flimflam::kTypeVPN); | 555 connecting_network = handler->ConnectingNetworkByType(flimflam::kTypeVPN); |
| 554 | 556 |
| 555 const NetworkState* network; | 557 const NetworkState* network; |
| 556 // If we are connecting to a network, and there is either no connected | 558 // If we are connecting to a network, and there is either no connected |
| 557 // network, or the connection was user requested, use the connecting | 559 // network, or the connection was user requested, use the connecting |
| (...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
| 611 | 613 |
| 612 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 614 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
| 613 tray::NetworkMessages::MessageMap::const_iterator iter = | 615 tray::NetworkMessages::MessageMap::const_iterator iter = |
| 614 messages()->messages().find(message_type); | 616 messages()->messages().find(message_type); |
| 615 if (iter != messages()->messages().end() && iter->second.delegate) | 617 if (iter != messages()->messages().end() && iter->second.delegate) |
| 616 iter->second.delegate->NotificationLinkClicked(message_type, link_id); | 618 iter->second.delegate->NotificationLinkClicked(message_type, link_id); |
| 617 } | 619 } |
| 618 | 620 |
| 619 } // namespace internal | 621 } // namespace internal |
| 620 } // namespace ash | 622 } // namespace ash |
| OLD | NEW |