| Index: ash/system/network/tray_network.cc
|
| diff --git a/ash/system/network/tray_network.cc b/ash/system/network/tray_network.cc
|
| index 6dc1e43bc696cfb07a4511b46a876af61f1f2d86..3081eea912c9f50663f7dc81b285b6ce80ebe522 100644
|
| --- a/ash/system/network/tray_network.cc
|
| +++ b/ash/system/network/tray_network.cc
|
| @@ -13,6 +13,7 @@
|
| #include "ash/system/network/network_icon_animation_observer.h"
|
| #include "ash/system/network/network_state_list_detailed_view.h"
|
| #include "ash/system/network/tray_network_state_observer.h"
|
| +#include "ash/system/system_notifier.h"
|
| #include "ash/system/tray/system_tray.h"
|
| #include "ash/system/tray/system_tray_delegate.h"
|
| #include "ash/system/tray/system_tray_notifier.h"
|
| @@ -29,28 +30,47 @@
|
| #include "ui/accessibility/ax_node_data.h"
|
| #include "ui/base/l10n/l10n_util.h"
|
| #include "ui/gfx/image/image_skia_operations.h"
|
| +#include "ui/message_center/message_center.h"
|
| +#include "ui/message_center/notification.h"
|
| #include "ui/views/controls/image_view.h"
|
| #include "ui/views/controls/link.h"
|
| #include "ui/views/controls/link_listener.h"
|
| -#include "ui/views/layout/box_layout.h"
|
| #include "ui/views/widget/widget.h"
|
|
|
| using chromeos::NetworkHandler;
|
| using chromeos::NetworkState;
|
| using chromeos::NetworkStateHandler;
|
| using chromeos::NetworkTypePattern;
|
| +using message_center::Notification;
|
|
|
| namespace ash {
|
| namespace tray {
|
|
|
| namespace {
|
|
|
| +constexpr char kWifiToggleNotificationId[] = "wifi-toggle";
|
| +
|
| // Returns the connected, non-virtual (aka VPN), network.
|
| const NetworkState* GetConnectedNetwork() {
|
| NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
|
| return handler->ConnectedNetworkByType(NetworkTypePattern::NonVirtual());
|
| }
|
|
|
| +std::unique_ptr<Notification> CreateNotification(bool wifi_enabled) {
|
| + const int string_id = wifi_enabled
|
| + ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
|
| + : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
|
| + std::unique_ptr<Notification> notification(new Notification(
|
| + message_center::NOTIFICATION_TYPE_SIMPLE, kWifiToggleNotificationId,
|
| + base::string16(), l10n_util::GetStringUTF16(string_id),
|
| + gfx::Image(network_icon::GetImageForWiFiEnabledState(wifi_enabled)),
|
| + base::string16() /* display_source */, GURL(),
|
| + message_center::NotifierId(message_center::NotifierId::SYSTEM_COMPONENT,
|
| + system_notifier::kNotifierWifiToggle),
|
| + message_center::RichNotificationData(), nullptr));
|
| + return notification;
|
| +}
|
| +
|
| } // namespace
|
|
|
| class NetworkTrayView : public TrayItemView,
|
| @@ -184,64 +204,13 @@ class NetworkDefaultView : public TrayItemMore,
|
| DISALLOW_COPY_AND_ASSIGN(NetworkDefaultView);
|
| };
|
|
|
| -class NetworkWifiDetailedView : public NetworkDetailedView {
|
| - public:
|
| - explicit NetworkWifiDetailedView(SystemTrayItem* owner)
|
| - : NetworkDetailedView(owner) {}
|
| -
|
| - ~NetworkWifiDetailedView() override {}
|
| -
|
| - // NetworkDetailedView:
|
| - void Init() override {
|
| - constexpr int kVerticalPadding = 10;
|
| - auto* box_layout = new views::BoxLayout(
|
| - views::BoxLayout::kHorizontal, kTrayPopupPaddingHorizontal,
|
| - kVerticalPadding, kTrayPopupPaddingBetweenItems);
|
| - SetLayoutManager(box_layout);
|
| -
|
| - image_view_ = new views::ImageView;
|
| - AddChildView(image_view_);
|
| -
|
| - label_view_ = new views::Label();
|
| - label_view_->SetHorizontalAlignment(gfx::ALIGN_LEFT);
|
| - AddChildView(label_view_);
|
| - box_layout->SetFlexForView(label_view_, 1);
|
| -
|
| - Update();
|
| - }
|
| -
|
| - NetworkDetailedView::DetailedViewType GetViewType() const override {
|
| - return NetworkDetailedView::WIFI_VIEW;
|
| - }
|
| -
|
| - void Update() override {
|
| - const bool wifi_enabled =
|
| - NetworkHandler::Get()->network_state_handler()->IsTechnologyEnabled(
|
| - NetworkTypePattern::WiFi());
|
| - image_view_->SetImage(
|
| - network_icon::GetImageForWiFiEnabledState(wifi_enabled));
|
| -
|
| - const int string_id = wifi_enabled
|
| - ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
|
| - : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
|
| - label_view_->SetText(l10n_util::GetStringUTF16(string_id));
|
| - }
|
| -
|
| - private:
|
| - views::ImageView* image_view_ = nullptr;
|
| - views::Label* label_view_ = nullptr;
|
| -
|
| - DISALLOW_COPY_AND_ASSIGN(NetworkWifiDetailedView);
|
| -};
|
| -
|
| } // namespace tray
|
|
|
| TrayNetwork::TrayNetwork(SystemTray* system_tray)
|
| : SystemTrayItem(system_tray, UMA_NETWORK),
|
| tray_(NULL),
|
| default_(NULL),
|
| - detailed_(NULL),
|
| - request_wifi_view_(false) {
|
| + detailed_(NULL) {
|
| network_state_observer_.reset(new TrayNetworkStateObserver(this));
|
| SystemTrayNotifier* notifier = Shell::Get()->system_tray_notifier();
|
| notifier->AddNetworkObserver(this);
|
| @@ -278,13 +247,8 @@ views::View* TrayNetwork::CreateDetailedView(LoginStatus status) {
|
| UMA_STATUS_AREA_DETAILED_NETWORK_VIEW);
|
| if (!chromeos::NetworkHandler::IsInitialized())
|
| return NULL;
|
| - if (request_wifi_view_) {
|
| - detailed_ = new tray::NetworkWifiDetailedView(this);
|
| - request_wifi_view_ = false;
|
| - } else {
|
| - detailed_ = new tray::NetworkStateListDetailedView(
|
| - this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status);
|
| - }
|
| + detailed_ = new tray::NetworkStateListDetailedView(
|
| + this, tray::NetworkStateListDetailedView::LIST_TYPE_NETWORK, status);
|
| detailed_->Init();
|
| return detailed_;
|
| }
|
| @@ -303,17 +267,19 @@ void TrayNetwork::DestroyDetailedView() {
|
|
|
| void TrayNetwork::RequestToggleWifi() {
|
| // This will always be triggered by a user action (e.g. keyboard shortcut)
|
| - if (!detailed_ ||
|
| - detailed_->GetViewType() == tray::NetworkDetailedView::WIFI_VIEW) {
|
| - request_wifi_view_ = true;
|
| - ShowDetailedView(kTrayPopupAutoCloseDelayForTextInSeconds, false);
|
| - }
|
| NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
|
| bool enabled = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi());
|
| ShellPort::Get()->RecordUserMetricsAction(
|
| enabled ? UMA_STATUS_AREA_DISABLE_WIFI : UMA_STATUS_AREA_ENABLE_WIFI);
|
| handler->SetTechnologyEnabled(NetworkTypePattern::WiFi(), !enabled,
|
| chromeos::network_handler::ErrorCallback());
|
| + message_center::MessageCenter* message_center =
|
| + message_center::MessageCenter::Get();
|
| + if (message_center->FindVisibleNotificationById(
|
| + tray::kWifiToggleNotificationId)) {
|
| + message_center->RemoveNotification(tray::kWifiToggleNotificationId, false);
|
| + }
|
| + message_center->AddNotification(tray::CreateNotification(!enabled));
|
| }
|
|
|
| void TrayNetwork::OnCaptivePortalDetected(const std::string& /* guid */) {
|
|
|