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_list_detailed_view.h" | 10 #include "ash/system/chromeos/network/network_list_detailed_view.h" |
11 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" | 11 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" |
12 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" | 12 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
13 #include "ash/system/chromeos/network/tray_network_state_observer.h" | |
14 #include "ash/system/tray/system_tray.h" | 13 #include "ash/system/tray/system_tray.h" |
15 #include "ash/system/tray/system_tray_delegate.h" | 14 #include "ash/system/tray/system_tray_delegate.h" |
16 #include "ash/system/tray/system_tray_notifier.h" | 15 #include "ash/system/tray/system_tray_notifier.h" |
17 #include "ash/system/tray/tray_constants.h" | 16 #include "ash/system/tray/tray_constants.h" |
18 #include "ash/system/tray/tray_item_more.h" | 17 #include "ash/system/tray/tray_item_more.h" |
19 #include "ash/system/tray/tray_item_view.h" | 18 #include "ash/system/tray/tray_item_view.h" |
20 #include "ash/system/tray/tray_notification_view.h" | 19 #include "ash/system/tray/tray_notification_view.h" |
21 #include "base/command_line.h" | 20 #include "base/command_line.h" |
22 #include "base/utf_string_conversions.h" | 21 #include "base/utf_string_conversions.h" |
23 #include "chromeos/chromeos_switches.h" | |
24 #include "chromeos/network/network_configuration_handler.h" | |
25 #include "chromeos/network/network_state.h" | 22 #include "chromeos/network/network_state.h" |
26 #include "chromeos/network/network_state_handler.h" | 23 #include "chromeos/network/network_state_handler.h" |
27 #include "grit/ash_resources.h" | 24 #include "grit/ash_resources.h" |
28 #include "grit/ash_strings.h" | 25 #include "grit/ash_strings.h" |
29 #include "third_party/cros_system_api/dbus/service_constants.h" | 26 #include "third_party/cros_system_api/dbus/service_constants.h" |
30 #include "ui/base/accessibility/accessible_view_state.h" | 27 #include "ui/base/accessibility/accessible_view_state.h" |
31 #include "ui/base/l10n/l10n_util.h" | 28 #include "ui/base/l10n/l10n_util.h" |
32 #include "ui/base/resource/resource_bundle.h" | 29 #include "ui/base/resource/resource_bundle.h" |
33 #include "ui/views/controls/link.h" | 30 #include "ui/views/controls/link.h" |
34 #include "ui/views/controls/link_listener.h" | 31 #include "ui/views/controls/link_listener.h" |
(...skipping 365 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
400 | 397 |
401 } // namespace tray | 398 } // namespace tray |
402 | 399 |
403 TrayNetwork::TrayNetwork(SystemTray* system_tray) | 400 TrayNetwork::TrayNetwork(SystemTray* system_tray) |
404 : SystemTrayItem(system_tray), | 401 : SystemTrayItem(system_tray), |
405 tray_(NULL), | 402 tray_(NULL), |
406 default_(NULL), | 403 default_(NULL), |
407 detailed_(NULL), | 404 detailed_(NULL), |
408 notification_(NULL), | 405 notification_(NULL), |
409 messages_(new tray::NetworkMessages()), | 406 messages_(new tray::NetworkMessages()), |
410 request_wifi_view_(false), | 407 request_wifi_view_(false) { |
411 uninitialized_msg_(0) { | |
412 if (UseNewNetworkHandlers()) | 408 if (UseNewNetworkHandlers()) |
413 network_state_observer_.reset(new TrayNetworkStateObserver(this)); | 409 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
414 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); | 410 Shell::GetInstance()->system_tray_notifier()->AddNetworkObserver(this); |
415 } | 411 } |
416 | 412 |
417 TrayNetwork::~TrayNetwork() { | 413 TrayNetwork::~TrayNetwork() { |
418 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); | 414 Shell::GetInstance()->system_tray_notifier()->RemoveNetworkObserver(this); |
419 } | 415 } |
420 | 416 |
421 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 417 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
(...skipping 16 matching lines...) Expand all Loading... | |
438 messages_->messages().clear(); | 434 messages_->messages().clear(); |
439 HideNotificationView(); | 435 HideNotificationView(); |
440 if (request_wifi_view_) { | 436 if (request_wifi_view_) { |
441 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); | 437 SystemTrayDelegate* delegate = Shell::GetInstance()->system_tray_delegate(); |
442 // The Wi-Fi state is not toggled yet at this point. | 438 // The Wi-Fi state is not toggled yet at this point. |
443 detailed_ = new tray::NetworkWifiDetailedView(this, | 439 detailed_ = new tray::NetworkWifiDetailedView(this, |
444 !delegate->GetWifiEnabled()); | 440 !delegate->GetWifiEnabled()); |
445 request_wifi_view_ = false; | 441 request_wifi_view_ = false; |
446 } else { | 442 } else { |
447 if (UseNewNetworkHandlers()) { | 443 if (UseNewNetworkHandlers()) { |
448 detailed_ = new tray::NetworkStateListDetailedView(this, status); | 444 detailed_ = new tray::NetworkStateListDetailedView( |
445 this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status); | |
449 } else { | 446 } else { |
450 detailed_ = new tray::NetworkListDetailedView( | 447 detailed_ = new tray::NetworkListDetailedView( |
451 this, status, IDS_ASH_STATUS_TRAY_NETWORK); | 448 this, status, IDS_ASH_STATUS_TRAY_NETWORK); |
452 } | 449 } |
453 detailed_->Init(); | 450 detailed_->Init(); |
454 } | 451 } |
455 return detailed_; | 452 return detailed_; |
456 } | 453 } |
457 | 454 |
458 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { | 455 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { |
(...skipping 56 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
515 HideNotificationView(); | 512 HideNotificationView(); |
516 return; | 513 return; |
517 } | 514 } |
518 if (notification_) | 515 if (notification_) |
519 notification_->Update(); | 516 notification_->Update(); |
520 else | 517 else |
521 ShowNotificationView(); | 518 ShowNotificationView(); |
522 } | 519 } |
523 | 520 |
524 void TrayNetwork::OnWillToggleWifi() { | 521 void TrayNetwork::OnWillToggleWifi() { |
525 if (UseNewNetworkHandlers()) | 522 // Triggered by a user action (e.g. keyboard shortcut) |
526 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged() | |
527 if (!detailed_ || | 523 if (!detailed_ || |
528 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { | 524 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { |
529 request_wifi_view_ = true; | 525 request_wifi_view_ = true; |
530 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 526 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
531 } | 527 } |
532 } | 528 } |
533 | 529 |
534 void TrayNetwork::TrayNetworkUpdated() { | 530 void TrayNetwork::NetworkStateChanged(bool list_changed) { |
535 if (tray_ && UseNewNetworkHandlers()) | 531 if (tray_ && UseNewNetworkHandlers()) |
536 tray_->UpdateNetworkStateHandlerIcon(); | 532 tray_->UpdateNetworkStateHandlerIcon(); |
537 if (default_) | 533 if (default_) |
538 default_->Update(); | 534 default_->Update(); |
535 if (detailed_) { | |
536 if (list_changed) | |
537 detailed_->NetworkListChanged(); | |
538 else | |
539 detailed_->ManagerChanged(); | |
540 } | |
539 } | 541 } |
540 | 542 |
541 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { | 543 void TrayNetwork::NetworkServiceChanged(const chromeos::NetworkState* network) { |
542 if (!network->IsConnectingState()) | 544 if (detailed_) |
543 connecting_networks_.erase(network->path()); | 545 detailed_->NetworkServiceChanged(network); |
544 } | |
545 | |
546 void TrayNetwork::ConnectToNetwork(const std::string& service_path) { | |
stevenjb
2013/03/02 03:14:45
The only reason this was here instead of NetworkSt
| |
547 DCHECK(UseNewNetworkHandlers()); | |
548 const NetworkState* network = | |
549 NetworkStateHandler::Get()->GetNetworkState(service_path); | |
550 if (!network) | |
551 return; | |
552 if (CommandLine::ForCurrentProcess()->HasSwitch( | |
553 chromeos::switches::kEnableNewNetworkConfigurationHandlers) && | |
554 !network->IsConnectedState()) { | |
555 chromeos::NetworkConfigurationHandler::Get()->Connect( | |
556 service_path, | |
557 base::Bind(&base::DoNothing), | |
558 chromeos::network_handler::ErrorCallback()); | |
559 connecting_networks_.insert(service_path); | |
560 } else { | |
561 // This will show the settings UI for a connected network. | |
562 // TODO(stevenjb): Change the API to explicitly show network settings. | |
563 Shell::GetInstance()->system_tray_delegate()->ConnectToNetwork( | |
564 service_path); | |
565 } | |
566 } | |
567 | |
568 bool TrayNetwork::HasConnectingNetwork(const std::string& service_path) { | |
569 return connecting_networks_.count(service_path) > 0; | |
570 } | 546 } |
571 | 547 |
572 void TrayNetwork::GetNetworkStateHandlerImageAndLabel( | 548 void TrayNetwork::GetNetworkStateHandlerImageAndLabel( |
573 network_icon::IconType icon_type, | 549 network_icon::IconType icon_type, |
574 gfx::ImageSkia* image, | 550 gfx::ImageSkia* image, |
575 string16* label) { | 551 string16* label) { |
576 NetworkStateHandler* handler = NetworkStateHandler::Get(); | 552 NetworkStateHandler* handler = NetworkStateHandler::Get(); |
577 const NetworkState* network = handler->ConnectedNetworkByType( | 553 const NetworkState* network = handler->ConnectedNetworkByType( |
578 NetworkStateHandler::kMatchTypeNonVirtual); | 554 NetworkStateHandler::kMatchTypeNonVirtual); |
579 if (network && network->type() == flimflam::kTypeEthernet && | 555 if (network && network->type() == flimflam::kTypeEthernet && |
580 icon_type == network_icon::ICON_TYPE_TRAY) { | 556 icon_type == network_icon::ICON_TYPE_TRAY) { |
581 *image = gfx::ImageSkia(); // Don't show ethernet in the tray. | 557 *image = gfx::ImageSkia(); // Don't show ethernet in the tray. |
582 return; | 558 return; |
583 } | 559 } |
584 const NetworkState* connecting_network = handler->ConnectingNetworkByType( | 560 const NetworkState* connecting_network = handler->ConnectingNetworkByType( |
585 NetworkStateHandler::kMatchTypeWireless); | 561 NetworkStateHandler::kMatchTypeWireless); |
586 // If we are connecting to a network, and there is either no connected | 562 // If we are connecting to a network, and there is either no connected |
587 // network, or the connection was user requested, use the connecting | 563 // network, or the connection was user requested, use the connecting |
588 // network. | 564 // network. |
589 if (connecting_network && | 565 if (connecting_network && |
590 (!network || | 566 (!network || TrayNetworkStateObserver::HasConnectingNetwork( |
591 HasConnectingNetwork(connecting_network->path()))) { | 567 connecting_network->path()))) { |
592 network = connecting_network; | 568 network = connecting_network; |
593 } | 569 } |
594 if (!network) { | 570 if (!network) { |
595 // If no connecting network, check for cellular initializing. | 571 // If no connecting network, check for cellular initializing. |
596 int uninitialized_msg = GetUninitializedMsg(); | 572 int uninitialized_msg = network_icon::GetCellularUninitializedMsg(); |
597 if (uninitialized_msg != 0) { | 573 if (uninitialized_msg != 0) { |
598 *image = network_icon::GetImageForConnectingNetwork( | 574 *image = network_icon::GetImageForConnectingNetwork( |
599 icon_type, flimflam::kTypeCellular); | 575 icon_type, flimflam::kTypeCellular); |
600 if (label) | 576 if (label) |
601 *label = l10n_util::GetStringUTF16(uninitialized_msg); | 577 *label = l10n_util::GetStringUTF16(uninitialized_msg); |
602 } else { | 578 } else { |
603 // Otherwise show the disconnected wifi icon. | 579 // Otherwise show the disconnected wifi icon. |
604 *image = network_icon::GetImageForDisconnectedNetwork( | 580 *image = network_icon::GetImageForDisconnectedNetwork( |
605 icon_type, flimflam::kTypeWifi); | 581 icon_type, flimflam::kTypeWifi); |
606 if (label) { | 582 if (label) { |
607 *label = l10n_util::GetStringUTF16( | 583 *label = l10n_util::GetStringUTF16( |
608 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); | 584 IDS_ASH_STATUS_TRAY_NETWORK_NOT_CONNECTED); |
609 } | 585 } |
610 } | 586 } |
611 return; | 587 return; |
612 } | 588 } |
613 // Get icon and label for connected or connecting network. | 589 // Get icon and label for connected or connecting network. |
614 *image = network_icon::GetImageForNetwork(network, icon_type); | 590 *image = network_icon::GetImageForNetwork(network, icon_type); |
615 if (label) | 591 if (label) |
616 *label = network_icon::GetLabelForNetwork(network, icon_type); | 592 *label = network_icon::GetLabelForNetwork(network, icon_type); |
617 } | 593 } |
618 | 594 |
619 int TrayNetwork::GetUninitializedMsg() { | |
620 NetworkStateHandler* handler = NetworkStateHandler::Get(); | |
621 if (handler->TechnologyUninitialized( | |
622 NetworkStateHandler::kMatchTypeMobile)) { | |
623 uninitialized_msg_ = IDS_ASH_STATUS_TRAY_INITIALIZING_CELLULAR; | |
624 uninitialized_state_time_ = base::Time::Now(); | |
625 return uninitialized_msg_; | |
626 } else if (handler->GetScanningByType( | |
627 NetworkStateHandler::kMatchTypeMobile)) { | |
628 uninitialized_msg_ = IDS_ASH_STATUS_TRAY_CELLULAR_SCANNING; | |
629 uninitialized_state_time_ = base::Time::Now(); | |
630 return uninitialized_msg_; | |
631 } | |
632 // There can be a delay between leaving the Initializing state and when | |
633 // a Cellular device shows up, so keep showing the initializing | |
634 // animation for a bit to avoid flashing the disconnect icon. | |
635 const int kInitializingDelaySeconds = 1; | |
636 base::TimeDelta dtime = base::Time::Now() - uninitialized_state_time_; | |
637 if (dtime.InSeconds() < kInitializingDelaySeconds) | |
638 return uninitialized_msg_; | |
639 return 0; | |
640 } | |
641 | |
642 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 595 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
643 tray::NetworkMessages::MessageMap::const_iterator iter = | 596 tray::NetworkMessages::MessageMap::const_iterator iter = |
644 messages()->messages().find(message_type); | 597 messages()->messages().find(message_type); |
645 if (iter != messages()->messages().end() && iter->second.delegate) | 598 if (iter != messages()->messages().end() && iter->second.delegate) |
646 iter->second.delegate->NotificationLinkClicked(link_id); | 599 iter->second.delegate->NotificationLinkClicked(link_id); |
647 } | 600 } |
648 | 601 |
649 } // namespace internal | 602 } // namespace internal |
650 } // namespace ash | 603 } // namespace ash |
OLD | NEW |