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/shell.h" | 7 #include "ash/shell.h" |
8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" | 8 #include "ash/system/chromeos/network/network_list_detailed_view_base.h" |
| 9 #include "ash/system/chromeos/network/network_state_list_detailed_view.h" |
| 10 #include "ash/system/chromeos/network/tray_network_state_observer.h" |
9 #include "ash/system/tray/system_tray.h" | 11 #include "ash/system/tray/system_tray.h" |
10 #include "ash/system/tray/system_tray_delegate.h" | 12 #include "ash/system/tray/system_tray_delegate.h" |
11 #include "ash/system/tray/tray_constants.h" | 13 #include "ash/system/tray/tray_constants.h" |
12 #include "ash/system/tray/tray_item_more.h" | 14 #include "ash/system/tray/tray_item_more.h" |
13 #include "ash/system/tray/tray_item_view.h" | 15 #include "ash/system/tray/tray_item_view.h" |
14 #include "ash/system/tray/tray_notification_view.h" | 16 #include "ash/system/tray/tray_notification_view.h" |
| 17 #include "base/command_line.h" |
| 18 #include "chromeos/chromeos_switches.h" |
| 19 #include "chromeos/network/network_state_handler.h" |
15 #include "grit/ash_resources.h" | 20 #include "grit/ash_resources.h" |
16 #include "grit/ash_strings.h" | 21 #include "grit/ash_strings.h" |
| 22 #include "third_party/cros_system_api/dbus/service_constants.h" |
17 #include "ui/base/l10n/l10n_util.h" | 23 #include "ui/base/l10n/l10n_util.h" |
18 #include "ui/base/resource/resource_bundle.h" | 24 #include "ui/base/resource/resource_bundle.h" |
19 #include "ui/views/controls/link.h" | 25 #include "ui/views/controls/link.h" |
20 #include "ui/views/controls/link_listener.h" | 26 #include "ui/views/controls/link_listener.h" |
21 #include "ui/views/layout/box_layout.h" | 27 #include "ui/views/layout/box_layout.h" |
22 | 28 |
23 namespace { | 29 namespace { |
24 | 30 |
25 using ash::internal::TrayNetwork; | 31 using ash::internal::TrayNetwork; |
26 | 32 |
(...skipping 53 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
80 | 86 |
81 MessageMap& messages() { return messages_; } | 87 MessageMap& messages() { return messages_; } |
82 const MessageMap& messages() const { return messages_; } | 88 const MessageMap& messages() const { return messages_; } |
83 | 89 |
84 private: | 90 private: |
85 MessageMap messages_; | 91 MessageMap messages_; |
86 }; | 92 }; |
87 | 93 |
88 class NetworkTrayView : public TrayItemView { | 94 class NetworkTrayView : public TrayItemView { |
89 public: | 95 public: |
90 NetworkTrayView(SystemTrayItem* owner, ColorTheme size, bool tray_icon) | 96 NetworkTrayView(SystemTrayItem* owner, ColorTheme size) |
91 : TrayItemView(owner), color_theme_(size), tray_icon_(tray_icon) { | 97 : TrayItemView(owner), color_theme_(size) { |
92 SetLayoutManager( | 98 SetLayoutManager( |
93 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); | 99 new views::BoxLayout(views::BoxLayout::kHorizontal, 0, 0, 0)); |
94 | 100 |
95 image_view_ = color_theme_ == DARK ? | 101 image_view_ = color_theme_ == DARK ? |
96 new FixedSizedImageView(0, kTrayPopupItemHeight) : | 102 new FixedSizedImageView(0, kTrayPopupItemHeight) : |
97 new views::ImageView; | 103 new views::ImageView; |
98 AddChildView(image_view_); | 104 AddChildView(image_view_); |
99 | 105 |
100 NetworkIconInfo info; | 106 NetworkIconInfo info; |
101 Shell::GetInstance()->tray_delegate()-> | 107 Shell::GetInstance()->tray_delegate()-> |
102 GetMostRelevantNetworkIcon(&info, false); | 108 GetMostRelevantNetworkIcon(&info, false); |
103 Update(info); | 109 Update(info); |
104 } | 110 } |
105 | 111 |
106 virtual ~NetworkTrayView() {} | 112 virtual ~NetworkTrayView() {} |
107 | 113 |
108 void Update(const NetworkIconInfo& info) { | 114 void Update(const NetworkIconInfo& info) { |
109 image_view_->SetImage(info.image); | 115 image_view_->SetImage(info.image); |
110 if (tray_icon_) | 116 SetVisible(info.tray_icon_visible); |
111 SetVisible(info.tray_icon_visible); | |
112 SchedulePaint(); | 117 SchedulePaint(); |
113 } | 118 } |
114 | 119 |
115 private: | 120 private: |
116 views::ImageView* image_view_; | 121 views::ImageView* image_view_; |
117 ColorTheme color_theme_; | 122 ColorTheme color_theme_; |
118 bool tray_icon_; | |
119 | 123 |
120 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); | 124 DISALLOW_COPY_AND_ASSIGN(NetworkTrayView); |
121 }; | 125 }; |
122 | 126 |
123 class NetworkDefaultView : public TrayItemMore { | 127 class NetworkDefaultView : public TrayItemMore { |
124 public: | 128 public: |
125 NetworkDefaultView(SystemTrayItem* owner, bool show_more) | 129 NetworkDefaultView(SystemTrayItem* owner, bool show_more) |
126 : TrayItemMore(owner, show_more) { | 130 : TrayItemMore(owner, show_more) { |
127 Update(); | 131 Update(); |
128 } | 132 } |
(...skipping 269 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
398 | 402 |
399 // Overridden from NetworkDetailedView: | 403 // Overridden from NetworkDetailedView: |
400 | 404 |
401 virtual void Init() OVERRIDE { | 405 virtual void Init() OVERRIDE { |
402 } | 406 } |
403 | 407 |
404 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { | 408 virtual NetworkDetailedView::DetailedViewType GetViewType() const OVERRIDE { |
405 return NetworkDetailedView::WIFI_VIEW; | 409 return NetworkDetailedView::WIFI_VIEW; |
406 } | 410 } |
407 | 411 |
408 virtual void Update() OVERRIDE {} | 412 virtual void ManagerChanged() OVERRIDE { |
| 413 } |
| 414 |
| 415 virtual void NetworkListChanged(const NetworkStateList& networks) OVERRIDE { |
| 416 } |
| 417 |
| 418 virtual void NetworkServiceChanged( |
| 419 const chromeos::NetworkState* network) OVERRIDE { |
| 420 } |
409 | 421 |
410 private: | 422 private: |
411 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); | 423 DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView); |
412 }; | 424 }; |
413 | 425 |
414 class NetworkMessageView : public views::View, | 426 class NetworkMessageView : public views::View, |
415 public views::LinkListener { | 427 public views::LinkListener { |
416 public: | 428 public: |
417 NetworkMessageView(TrayNetwork* owner, | 429 NetworkMessageView(TrayNetwork* owner, |
418 TrayNetwork::MessageType message_type, | 430 TrayNetwork::MessageType message_type, |
(...skipping 103 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
522 } // namespace tray | 534 } // namespace tray |
523 | 535 |
524 TrayNetwork::TrayNetwork(SystemTray* system_tray) | 536 TrayNetwork::TrayNetwork(SystemTray* system_tray) |
525 : SystemTrayItem(system_tray), | 537 : SystemTrayItem(system_tray), |
526 tray_(NULL), | 538 tray_(NULL), |
527 default_(NULL), | 539 default_(NULL), |
528 detailed_(NULL), | 540 detailed_(NULL), |
529 notification_(NULL), | 541 notification_(NULL), |
530 messages_(new tray::NetworkMessages()), | 542 messages_(new tray::NetworkMessages()), |
531 request_wifi_view_(false) { | 543 request_wifi_view_(false) { |
| 544 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 545 chromeos::switches::kEnableNewNetworkHandlers)) { |
| 546 network_state_observer_.reset(new TrayNetworkStateObserver(this)); |
| 547 } |
532 } | 548 } |
533 | 549 |
534 TrayNetwork::~TrayNetwork() { | 550 TrayNetwork::~TrayNetwork() { |
535 } | 551 } |
536 | 552 |
537 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { | 553 views::View* TrayNetwork::CreateTrayView(user::LoginStatus status) { |
538 CHECK(tray_ == NULL); | 554 CHECK(tray_ == NULL); |
539 tray_ = new tray::NetworkTrayView(this, tray::LIGHT, true /*tray_icon*/); | 555 tray_ = new tray::NetworkTrayView(this, tray::LIGHT); |
540 return tray_; | 556 return tray_; |
541 } | 557 } |
542 | 558 |
543 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { | 559 views::View* TrayNetwork::CreateDefaultView(user::LoginStatus status) { |
544 CHECK(default_ == NULL); | 560 CHECK(default_ == NULL); |
545 default_ = | 561 default_ = |
546 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); | 562 new tray::NetworkDefaultView(this, status != user::LOGGED_IN_LOCKED); |
547 return default_; | 563 return default_; |
548 } | 564 } |
549 | 565 |
550 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { | 566 views::View* TrayNetwork::CreateDetailedView(user::LoginStatus status) { |
551 CHECK(detailed_ == NULL); | 567 CHECK(detailed_ == NULL); |
552 // Clear any notifications when showing the detailed view. | 568 // Clear any notifications when showing the detailed view. |
553 messages_->messages().clear(); | 569 messages_->messages().clear(); |
554 HideNotificationView(); | 570 HideNotificationView(); |
555 if (request_wifi_view_) { | 571 if (request_wifi_view_) { |
556 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); | 572 SystemTrayDelegate* delegate = Shell::GetInstance()->tray_delegate(); |
557 // The Wi-Fi state is not toggled yet at this point. | 573 // The Wi-Fi state is not toggled yet at this point. |
558 detailed_ = new tray::NetworkWifiDetailedView(this, | 574 detailed_ = new tray::NetworkWifiDetailedView(this, |
559 !delegate->GetWifiEnabled()); | 575 !delegate->GetWifiEnabled()); |
560 request_wifi_view_ = false; | 576 request_wifi_view_ = false; |
561 } else { | 577 } else { |
562 detailed_ = new tray::NetworkListDetailedView( | 578 if (CommandLine::ForCurrentProcess()->HasSwitch( |
563 this, status, IDS_ASH_STATUS_TRAY_NETWORK); | 579 chromeos::switches::kEnableNewNetworkHandlers)) { |
| 580 detailed_ = new tray::NetworkStateListDetailedView(this, status); |
| 581 } else { |
| 582 detailed_ = new tray::NetworkListDetailedView( |
| 583 this, status, IDS_ASH_STATUS_TRAY_NETWORK); |
| 584 } |
564 detailed_->Init(); | 585 detailed_->Init(); |
565 } | 586 } |
566 return detailed_; | 587 return detailed_; |
567 } | 588 } |
568 | 589 |
569 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { | 590 views::View* TrayNetwork::CreateNotificationView(user::LoginStatus status) { |
570 CHECK(notification_ == NULL); | 591 CHECK(notification_ == NULL); |
571 if (messages_->messages().empty()) | 592 if (messages_->messages().empty()) |
572 return NULL; // Message has already been cleared. | 593 return NULL; // Message has already been cleared. |
573 notification_ = new tray::NetworkNotificationView(this); | 594 notification_ = new tray::NetworkNotificationView(this); |
(...skipping 22 matching lines...) Expand all Loading... |
596 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { | 617 void TrayNetwork::UpdateAfterShelfAlignmentChange(ShelfAlignment alignment) { |
597 SetTrayImageItemBorder(tray_, alignment); | 618 SetTrayImageItemBorder(tray_, alignment); |
598 } | 619 } |
599 | 620 |
600 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { | 621 void TrayNetwork::OnNetworkRefresh(const NetworkIconInfo& info) { |
601 if (tray_) | 622 if (tray_) |
602 tray_->Update(info); | 623 tray_->Update(info); |
603 if (default_) | 624 if (default_) |
604 default_->Update(); | 625 default_->Update(); |
605 if (detailed_) | 626 if (detailed_) |
606 detailed_->Update(); | 627 detailed_->ManagerChanged(); |
607 } | 628 } |
608 | 629 |
609 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, | 630 void TrayNetwork::SetNetworkMessage(NetworkTrayDelegate* delegate, |
610 MessageType message_type, | 631 MessageType message_type, |
611 NetworkType network_type, | 632 NetworkType network_type, |
612 const string16& title, | 633 const string16& title, |
613 const string16& message, | 634 const string16& message, |
614 const std::vector<string16>& links) { | 635 const std::vector<string16>& links) { |
615 messages_->messages()[message_type] = tray::NetworkMessages::Message( | 636 messages_->messages()[message_type] = tray::NetworkMessages::Message( |
616 delegate, network_type, title, message, links); | 637 delegate, network_type, title, message, links); |
617 if (notification_) | 638 if (notification_) |
618 notification_->Update(); | 639 notification_->Update(); |
619 else | 640 else |
620 ShowNotificationView(); | 641 ShowNotificationView(); |
621 } | 642 } |
622 | 643 |
623 void TrayNetwork::ClearNetworkMessage(MessageType message_type) { | 644 void TrayNetwork::ClearNetworkMessage(MessageType message_type) { |
624 messages_->messages().erase(message_type); | 645 messages_->messages().erase(message_type); |
625 if (messages_->messages().empty()) { | 646 if (messages_->messages().empty()) { |
626 HideNotificationView(); | 647 HideNotificationView(); |
627 return; | 648 return; |
628 } | 649 } |
629 if (notification_) | 650 if (notification_) |
630 notification_->Update(); | 651 notification_->Update(); |
631 else | 652 else |
632 ShowNotificationView(); | 653 ShowNotificationView(); |
633 } | 654 } |
634 | 655 |
635 void TrayNetwork::OnWillToggleWifi() { | 656 void TrayNetwork::OnWillToggleWifi() { |
| 657 if (CommandLine::ForCurrentProcess()->HasSwitch( |
| 658 chromeos::switches::kEnableNewNetworkHandlers)) { |
| 659 return; // Handled in TrayNetworkStateObserver::NetworkManagerChanged() |
| 660 } |
636 if (!detailed_ || | 661 if (!detailed_ || |
637 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { | 662 detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) { |
638 request_wifi_view_ = true; | 663 request_wifi_view_ = true; |
639 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); | 664 PopupDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false); |
640 } | 665 } |
641 } | 666 } |
642 | 667 |
643 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { | 668 void TrayNetwork::LinkClicked(MessageType message_type, int link_id) { |
644 tray::NetworkMessages::MessageMap::const_iterator iter = | 669 tray::NetworkMessages::MessageMap::const_iterator iter = |
645 messages()->messages().find(message_type); | 670 messages()->messages().find(message_type); |
646 if (iter != messages()->messages().end() && iter->second.delegate) | 671 if (iter != messages()->messages().end() && iter->second.delegate) |
647 iter->second.delegate->NotificationLinkClicked(link_id); | 672 iter->second.delegate->NotificationLinkClicked(link_id); |
648 } | 673 } |
649 | 674 |
650 } // namespace internal | 675 } // namespace internal |
651 } // namespace ash | 676 } // namespace ash |
OLD | NEW |