Commit c6f5e538 authored by mohsen's avatar mohsen Committed by Commit bot

Remove NetworkListDelegate

NetworkListDelegate was introduced when parts of network UI were living
in a different component. Now that everything is in //ash/system/network
there is no need for the delegate. NetworkListView and VPNListView can
access its methods directly from NetworkStateListDetailedView. Also,
some of the functionality was only used in NetworkListView and moved to
that class.

This is the first step to clean up code for network and VPN detailed
views necessary to share code between all detailed views.

BUG=686343
TEST=none

Review-Url: https://codereview.chromium.org/2843163003
Cr-Commit-Position: refs/heads/master@{#468227}
parent 00f09058
...@@ -380,7 +380,6 @@ component("ash") { ...@@ -380,7 +380,6 @@ component("ash") {
"system/network/network_info.h", "system/network/network_info.h",
"system/network/network_list.cc", "system/network/network_list.cc",
"system/network/network_list.h", "system/network/network_list.h",
"system/network/network_list_delegate.h",
"system/network/network_list_view_base.cc", "system/network/network_list_view_base.cc",
"system/network/network_list_view_base.h", "system/network/network_list_view_base.h",
"system/network/network_observer.h", "system/network/network_observer.h",
......
...@@ -4,18 +4,29 @@ ...@@ -4,18 +4,29 @@
#include "ash/system/network/network_list.h" #include "ash/system/network/network_list.h"
#include <stddef.h> #include <memory>
#include "ash/shell.h"
#include "ash/shell_port.h"
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "ash/system/network/network_icon_animation.h" #include "ash/system/network/network_icon_animation.h"
#include "ash/system/network/network_list_delegate.h" #include "ash/system/network/network_info.h"
#include "ash/system/network/network_state_list_detailed_view.h"
#include "ash/system/networking_config_delegate.h"
#include "ash/system/tray/fixed_sized_image_view.h"
#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_menu_button.h" #include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/system_tray_controller.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/throbber_view.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_popup_item_style.h" #include "ash/system/tray/tray_popup_item_style.h"
#include "ash/system/tray/tray_popup_utils.h" #include "ash/system/tray/tray_popup_utils.h"
#include "ash/system/tray/tri_view.h" #include "ash/system/tray/tri_view.h"
#include "base/memory/ptr_util.h" #include "base/memory/ptr_util.h"
#include "base/strings/string16.h"
#include "base/strings/utf_string_conversions.h"
#include "chromeos/dbus/dbus_thread_manager.h" #include "chromeos/dbus/dbus_thread_manager.h"
#include "chromeos/dbus/power_manager/power_supply_properties.pb.h" #include "chromeos/dbus/power_manager/power_supply_properties.pb.h"
#include "chromeos/dbus/power_manager_client.h" #include "chromeos/dbus/power_manager_client.h"
...@@ -26,12 +37,16 @@ ...@@ -26,12 +37,16 @@
#include "chromeos/network/network_state_handler_observer.h" #include "chromeos/network/network_state_handler_observer.h"
#include "chromeos/network/proxy/ui_proxy_config_service.h" #include "chromeos/network/proxy/ui_proxy_config_service.h"
#include "components/device_event_log/device_event_log.h" #include "components/device_event_log/device_event_log.h"
#include "third_party/skia/include/core/SkColor.h"
#include "ui/base/l10n/l10n_util.h" #include "ui/base/l10n/l10n_util.h"
#include "ui/base/resource/resource_bundle.h" #include "ui/base/resource/resource_bundle.h"
#include "ui/gfx/color_palette.h" #include "ui/gfx/color_palette.h"
#include "ui/gfx/font.h" #include "ui/gfx/font.h"
#include "ui/gfx/image/image_skia.h"
#include "ui/gfx/paint_vector_icon.h" #include "ui/gfx/paint_vector_icon.h"
#include "ui/gfx/text_constants.h"
#include "ui/views/background.h" #include "ui/views/background.h"
#include "ui/views/border.h"
#include "ui/views/controls/button/toggle_button.h" #include "ui/views/controls/button/toggle_button.h"
#include "ui/views/controls/image_view.h" #include "ui/views/controls/image_view.h"
#include "ui/views/controls/label.h" #include "ui/views/controls/label.h"
...@@ -73,6 +88,32 @@ bool IsProhibitedByPolicy(const chromeos::NetworkState* network) { ...@@ -73,6 +88,32 @@ bool IsProhibitedByPolicy(const chromeos::NetworkState* network) {
network->guid(), network->profile_path(), nullptr /* onc_source */); network->guid(), network->profile_path(), nullptr /* onc_source */);
} }
// TODO(varkha|mohsen): Consolidate with a similar method in
// BluetoothDetailedView (see https://crbug.com/686924).
void SetupConnectedItem(HoverHighlightView* container,
const base::string16& text,
const gfx::ImageSkia& image) {
container->AddIconAndLabels(
image, text,
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED));
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION);
style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED);
style.SetupLabel(container->sub_text_label());
}
// TODO(varkha|mohsen): Consolidate with a similar method in
// BluetoothDetailedView (see https://crbug.com/686924).
void SetupConnectingItem(HoverHighlightView* container,
const base::string16& text,
const gfx::ImageSkia& image) {
container->AddIconAndLabels(
image, text,
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
ThrobberView* throbber = new ThrobberView;
throbber->Start();
container->AddRightView(throbber);
}
} // namespace } // namespace
// A header row for sections in network detailed view which contains a title and // A header row for sections in network detailed view which contains a title and
...@@ -210,9 +251,8 @@ class TetherHeaderRowView : public NetworkListView::SectionHeaderRowView { ...@@ -210,9 +251,8 @@ class TetherHeaderRowView : public NetworkListView::SectionHeaderRowView {
class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView {
public: public:
explicit WifiHeaderRowView(NetworkListDelegate* network_list_delegate) WifiHeaderRowView()
: SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI), : SectionHeaderRowView(IDS_ASH_STATUS_TRAY_NETWORK_WIFI),
network_list_delegate_(network_list_delegate),
join_(nullptr) {} join_(nullptr) {}
~WifiHeaderRowView() override {} ~WifiHeaderRowView() override {}
...@@ -252,7 +292,10 @@ class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { ...@@ -252,7 +292,10 @@ class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView {
void ButtonPressed(views::Button* sender, const ui::Event& event) override { void ButtonPressed(views::Button* sender, const ui::Event& event) override {
if (sender == join_) { if (sender == join_) {
network_list_delegate_->OnOtherWifiClicked(); ShellPort::Get()->RecordUserMetricsAction(
UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED);
Shell::Get()->system_tray_controller()->ShowNetworkCreate(
shill::kTypeWifi);
return; return;
} }
SectionHeaderRowView::ButtonPressed(sender, event); SectionHeaderRowView::ButtonPressed(sender, event);
...@@ -271,8 +314,6 @@ class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { ...@@ -271,8 +314,6 @@ class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView {
// .30 * .38 opacity for disabled icon. // .30 * .38 opacity for disabled icon.
static constexpr int kDisabledJoinIconAlpha = 0x1D; static constexpr int kDisabledJoinIconAlpha = 0x1D;
NetworkListDelegate* network_list_delegate_;
// A button to invoke "Join Wi-Fi network" dialog. // A button to invoke "Join Wi-Fi network" dialog.
SystemMenuButton* join_; SystemMenuButton* join_;
...@@ -283,9 +324,10 @@ class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView { ...@@ -283,9 +324,10 @@ class WifiHeaderRowView : public NetworkListView::SectionHeaderRowView {
// NetworkListView: // NetworkListView:
NetworkListView::NetworkListView(NetworkListDelegate* delegate) NetworkListView::NetworkListView(
: needs_relayout_(false), tray::NetworkStateListDetailedView* detailed_view)
delegate_(delegate), : NetworkListViewBase(detailed_view),
needs_relayout_(false),
no_wifi_networks_view_(nullptr), no_wifi_networks_view_(nullptr),
no_cellular_networks_view_(nullptr), no_cellular_networks_view_(nullptr),
cellular_header_view_(nullptr), cellular_header_view_(nullptr),
...@@ -294,9 +336,7 @@ NetworkListView::NetworkListView(NetworkListDelegate* delegate) ...@@ -294,9 +336,7 @@ NetworkListView::NetworkListView(NetworkListDelegate* delegate)
cellular_separator_view_(nullptr), cellular_separator_view_(nullptr),
tether_separator_view_(nullptr), tether_separator_view_(nullptr),
wifi_separator_view_(nullptr), wifi_separator_view_(nullptr),
connection_warning_(nullptr) { connection_warning_(nullptr) {}
CHECK(delegate_);
}
NetworkListView::~NetworkListView() { NetworkListView::~NetworkListView() {
network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
...@@ -345,9 +385,8 @@ void NetworkListView::UpdateNetworks( ...@@ -345,9 +385,8 @@ void NetworkListView::UpdateNetworks(
last_network_info_map_[info->guid] = std::move(info); last_network_info_map_[info->guid] = std::move(info);
network_list_.clear(); network_list_.clear();
const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern();
for (const auto* network : networks) { for (const auto* network : networks) {
if (!pattern.MatchesType(network->type())) if (!NetworkTypePattern::NonVirtual().MatchesType(network->type()))
continue; continue;
// Do not add Wi-Fi networks that are associated with a Tether network. // Do not add Wi-Fi networks that are associated with a Tether network.
...@@ -474,7 +513,7 @@ void NetworkListView::UpdateNetworkListInternal() { ...@@ -474,7 +513,7 @@ void NetworkListView::UpdateNetworkListInternal() {
} }
} }
container()->SizeToPreferredSize(); container()->SizeToPreferredSize();
delegate_->RelayoutScrollList(); detailed_view()->RelayoutScrollList();
if (selected_view) if (selected_view)
container()->ScrollRectToVisible(selected_view->bounds()); container()->ScrollRectToVisible(selected_view->bounds());
} }
...@@ -505,32 +544,29 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -505,32 +544,29 @@ NetworkListView::UpdateNetworkListEntries() {
UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index); UpdateNetworkChildren(NetworkInfo::Type::UNKNOWN, index);
index += new_guids->size(); index += new_guids->size();
const NetworkTypePattern pattern = delegate_->GetNetworkTypePattern(); if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) {
if (pattern.MatchesPattern(NetworkTypePattern::Cellular())) { index = UpdateSectionHeaderRow(
if (handler->IsTechnologyAvailable(NetworkTypePattern::Cellular())) { NetworkTypePattern::Cellular(),
index = UpdateSectionHeaderRow( handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index,
NetworkTypePattern::Cellular(), &cellular_header_view_, &cellular_separator_view_);
handler->IsTechnologyEnabled(NetworkTypePattern::Cellular()), index, }
&cellular_header_view_, &cellular_separator_view_);
}
// Cellular initializing.
int message_id = network_icon::GetCellularUninitializedMsg();
if (!message_id &&
handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) &&
!handler->FirstNetworkByType(NetworkTypePattern::Mobile())) {
message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS;
}
UpdateInfoLabel(message_id, index, &no_cellular_networks_view_);
if (message_id)
++index;
// Add cellular networks. // Cellular initializing.
std::unique_ptr<std::set<std::string>> new_cellular_guids = int cellular_message_id = network_icon::GetCellularUninitializedMsg();
UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index); if (!cellular_message_id &&
index += new_cellular_guids->size(); handler->IsTechnologyEnabled(NetworkTypePattern::Mobile()) &&
new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end()); !handler->FirstNetworkByType(NetworkTypePattern::Mobile())) {
cellular_message_id = IDS_ASH_STATUS_TRAY_NO_MOBILE_NETWORKS;
} }
UpdateInfoLabel(cellular_message_id, index, &no_cellular_networks_view_);
if (cellular_message_id)
++index;
// Add cellular networks.
std::unique_ptr<std::set<std::string>> new_cellular_guids =
UpdateNetworkChildren(NetworkInfo::Type::CELLULAR, index);
index += new_cellular_guids->size();
new_guids->insert(new_cellular_guids->begin(), new_cellular_guids->end());
// TODO (hansberry): Audit existing usage of NonVirtual and consider changing // TODO (hansberry): Audit existing usage of NonVirtual and consider changing
// it to include Tether. See crbug.com/693647. // it to include Tether. See crbug.com/693647.
...@@ -541,8 +577,8 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -541,8 +577,8 @@ NetworkListView::UpdateNetworkListEntries() {
&tether_header_view_, &tether_separator_view_); &tether_header_view_, &tether_separator_view_);
// TODO (hansberry): Should a message similar to // TODO (hansberry): Should a message similar to
// IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology // IDS_ASH_STATUS_TRAY_NO_CELLULAR_NETWORKS be shown if Tether technology is
// is enabled but no networks are around? // enabled but no networks are around?
// Add Tether networks. // Add Tether networks.
std::unique_ptr<std::set<std::string>> new_tether_guids = std::unique_ptr<std::set<std::string>> new_tether_guids =
...@@ -551,29 +587,27 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -551,29 +587,27 @@ NetworkListView::UpdateNetworkListEntries() {
new_guids->insert(new_tether_guids->begin(), new_tether_guids->end()); new_guids->insert(new_tether_guids->begin(), new_tether_guids->end());
} }
if (pattern.MatchesPattern(NetworkTypePattern::WiFi())) { index = UpdateSectionHeaderRow(
index = UpdateSectionHeaderRow( NetworkTypePattern::WiFi(),
NetworkTypePattern::WiFi(), handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index,
handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()), index, &wifi_header_view_, &wifi_separator_view_);
&wifi_header_view_, &wifi_separator_view_);
// "Wifi Enabled / Disabled".
// "Wifi Enabled / Disabled". int wifi_message_id = 0;
int message_id = 0; if (network_list_.empty()) {
if (network_list_.empty()) { wifi_message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi())
message_id = handler->IsTechnologyEnabled(NetworkTypePattern::WiFi()) ? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED
? IDS_ASH_STATUS_TRAY_NETWORK_WIFI_ENABLED : IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
: IDS_ASH_STATUS_TRAY_NETWORK_WIFI_DISABLED;
}
UpdateInfoLabel(message_id, index, &no_wifi_networks_view_);
if (message_id)
++index;
// Add Wi-Fi networks.
std::unique_ptr<std::set<std::string>> new_wifi_guids =
UpdateNetworkChildren(NetworkInfo::Type::WIFI, index);
index += new_wifi_guids->size();
new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end());
} }
UpdateInfoLabel(wifi_message_id, index, &no_wifi_networks_view_);
if (wifi_message_id)
++index;
// Add Wi-Fi networks.
std::unique_ptr<std::set<std::string>> new_wifi_guids =
UpdateNetworkChildren(NetworkInfo::Type::WIFI, index);
index += new_wifi_guids->size();
new_guids->insert(new_wifi_guids->begin(), new_wifi_guids->end());
// No networks or other messages (fallback). // No networks or other messages (fallback).
if (index == 0) { if (index == 0) {
...@@ -584,6 +618,63 @@ NetworkListView::UpdateNetworkListEntries() { ...@@ -584,6 +618,63 @@ NetworkListView::UpdateNetworkListEntries() {
return new_guids; return new_guids;
} }
HoverHighlightView* NetworkListView::CreateViewForNetwork(
const NetworkInfo& info) {
HoverHighlightView* container = new HoverHighlightView(detailed_view());
if (info.connected)
SetupConnectedItem(container, info.label, info.image);
else if (info.connecting)
SetupConnectingItem(container, info.label, info.image);
else
container->AddIconAndLabel(info.image, info.label);
container->SetTooltipText(info.tooltip);
views::View* controlled_icon = CreateControlledByExtensionView(info);
if (controlled_icon)
container->AddChildView(controlled_icon);
return container;
}
void NetworkListView::UpdateViewForNetwork(HoverHighlightView* view,
const NetworkInfo& info) {
DCHECK(!view->has_children());
if (info.connected)
SetupConnectedItem(view, info.label, info.image);
else if (info.connecting)
SetupConnectingItem(view, info.label, info.image);
else
view->AddIconAndLabel(info.image, info.label);
views::View* controlled_icon = CreateControlledByExtensionView(info);
view->SetTooltipText(info.tooltip);
if (controlled_icon)
view->AddChildView(controlled_icon);
}
views::View* NetworkListView::CreateControlledByExtensionView(
const NetworkInfo& info) {
NetworkingConfigDelegate* networking_config_delegate =
Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate();
if (!networking_config_delegate)
return nullptr;
std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo>
extension_info =
networking_config_delegate->LookUpExtensionForNetwork(info.guid);
if (!extension_info)
return nullptr;
// Get the tooltip text.
base::string16 tooltip_text = l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_EXTENSION_CONTROLLED_WIFI,
base::UTF8ToUTF16(extension_info->extension_name));
views::ImageView* controlled_icon =
new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
controlled_icon->SetImage(
gfx::CreateVectorIcon(kCaptivePortalIcon, kMenuIconColor));
controlled_icon->SetTooltipText(tooltip_text);
return controlled_icon;
}
std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren(
NetworkInfo::Type type, NetworkInfo::Type type,
int index) { int index) {
...@@ -598,15 +689,15 @@ std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren( ...@@ -598,15 +689,15 @@ std::unique_ptr<std::set<std::string>> NetworkListView::UpdateNetworkChildren(
} }
void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) { void NetworkListView::UpdateNetworkChild(int index, const NetworkInfo* info) {
views::View* network_view = nullptr; HoverHighlightView* network_view = nullptr;
NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid); NetworkGuidMap::const_iterator found = network_guid_map_.find(info->guid);
if (found == network_guid_map_.end()) { if (found == network_guid_map_.end()) {
network_view = delegate_->CreateViewForNetwork(*info); network_view = CreateViewForNetwork(*info);
} else { } else {
network_view = found->second; network_view = found->second;
if (NeedUpdateViewForNetwork(*info)) { if (NeedUpdateViewForNetwork(*info)) {
network_view->RemoveAllChildViews(true); network_view->RemoveAllChildViews(true);
delegate_->UpdateViewForNetwork(network_view, *info); UpdateViewForNetwork(network_view, *info);
network_view->Layout(); network_view->Layout();
network_view->SchedulePaint(); network_view->SchedulePaint();
} }
...@@ -643,8 +734,16 @@ void NetworkListView::UpdateInfoLabel(int message_id, ...@@ -643,8 +734,16 @@ void NetworkListView::UpdateInfoLabel(int message_id,
} }
base::string16 text = base::string16 text =
ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id); ui::ResourceBundle::GetSharedInstance().GetLocalizedString(message_id);
if (!label) if (!label) {
label = delegate_->CreateInfoLabel(); // TODO(mohsen): Update info label to follow MD specs. See
// https://crbug.com/687778.
label = new views::Label();
label->SetBorder(views::CreateEmptyBorder(
kTrayPopupPaddingBetweenItems, kTrayPopupPaddingHorizontal,
kTrayPopupPaddingBetweenItems, 0));
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0));
}
label->SetText(text); label->SetText(text);
PlaceViewAtIndex(label, insertion_index); PlaceViewAtIndex(label, insertion_index);
*label_ptr = label; *label_ptr = label;
...@@ -661,7 +760,7 @@ int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern, ...@@ -661,7 +760,7 @@ int NetworkListView::UpdateSectionHeaderRow(NetworkTypePattern pattern,
else if (pattern.Equals(NetworkTypePattern::Tether())) else if (pattern.Equals(NetworkTypePattern::Tether()))
*view = new TetherHeaderRowView(); *view = new TetherHeaderRowView();
else if (pattern.Equals(NetworkTypePattern::WiFi())) else if (pattern.Equals(NetworkTypePattern::WiFi()))
*view = new WifiHeaderRowView(delegate_); *view = new WifiHeaderRowView();
else else
NOTREACHED(); NOTREACHED();
(*view)->Init(enabled); (*view)->Init(enabled);
......
...@@ -26,9 +26,8 @@ class View; ...@@ -26,9 +26,8 @@ class View;
} }
namespace ash { namespace ash {
class HoverHighlightView;
struct NetworkInfo; struct NetworkInfo;
class NetworkListDelegate;
class TriView; class TriView;
// A list of available networks of a given type. This class is used for all // A list of available networks of a given type. This class is used for all
...@@ -38,7 +37,7 @@ class NetworkListView : public NetworkListViewBase, ...@@ -38,7 +37,7 @@ class NetworkListView : public NetworkListViewBase,
public: public:
class SectionHeaderRowView; class SectionHeaderRowView;
explicit NetworkListView(NetworkListDelegate* delegate); explicit NetworkListView(tray::NetworkStateListDetailedView* detailed_view);
~NetworkListView() override; ~NetworkListView() override;
// NetworkListViewBase: // NetworkListViewBase:
...@@ -72,6 +71,18 @@ class NetworkListView : public NetworkListViewBase, ...@@ -72,6 +71,18 @@ class NetworkListView : public NetworkListViewBase,
// being used. // being used.
TriView* CreateConnectionWarning(); TriView* CreateConnectionWarning();
// Creates and returns a View with the information in |info|.
HoverHighlightView* CreateViewForNetwork(const NetworkInfo& info);
// Updates |view| with the information in |info|. Note that |view| is
// guaranteed to be a View returned from |CreateViewForNetwork()|.
void UpdateViewForNetwork(HoverHighlightView* view, const NetworkInfo& info);
// Creates the view of an extra icon appearing next to the network name
// indicating that the network is controlled by an extension. If no extension
// is registered for this network, returns |nullptr|.
views::View* CreateControlledByExtensionView(const NetworkInfo& info);
// Adds or updates child views representing the network connections when // Adds or updates child views representing the network connections when
// |is_wifi| is matching the attribute of a network connection starting at // |is_wifi| is matching the attribute of a network connection starting at
// |child_index|. Returns a set of guids for the added network // |child_index|. Returns a set of guids for the added network
...@@ -112,7 +123,6 @@ class NetworkListView : public NetworkListViewBase, ...@@ -112,7 +123,6 @@ class NetworkListView : public NetworkListViewBase,
bool NeedUpdateViewForNetwork(const NetworkInfo& info) const; bool NeedUpdateViewForNetwork(const NetworkInfo& info) const;
bool needs_relayout_; bool needs_relayout_;
NetworkListDelegate* delegate_;
views::Label* no_wifi_networks_view_; views::Label* no_wifi_networks_view_;
views::Label* no_cellular_networks_view_; views::Label* no_cellular_networks_view_;
...@@ -131,7 +141,7 @@ class NetworkListView : public NetworkListViewBase, ...@@ -131,7 +141,7 @@ class NetworkListView : public NetworkListViewBase,
NetworkMap network_map_; NetworkMap network_map_;
// A map of network guids to their view. // A map of network guids to their view.
using NetworkGuidMap = std::map<std::string, views::View*>; using NetworkGuidMap = std::map<std::string, HoverHighlightView*>;
NetworkGuidMap network_guid_map_; NetworkGuidMap network_guid_map_;
// Save a map of network guids to their infos against current |network_list_|. // Save a map of network guids to their infos against current |network_list_|.
......
// Copyright 2014 The Chromium Authors. All rights reserved.
// Use of this source code is governed by a BSD-style license that can be
// found in the LICENSE file.
#ifndef ASH_SYSTEM_NETWORK_NETWORK_LIST_DELEGATE_H_
#define ASH_SYSTEM_NETWORK_NETWORK_LIST_DELEGATE_H_
namespace chromeos {
class NetworkTypePattern;
}
namespace views {
class Label;
class View;
}
namespace ash {
struct NetworkInfo;
class NetworkListDelegate {
public:
virtual ~NetworkListDelegate() {}
// Creates and returns a View with the information in |info|.
virtual views::View* CreateViewForNetwork(const NetworkInfo& info) = 0;
// Returns the type of network this list should use.
virtual chromeos::NetworkTypePattern GetNetworkTypePattern() const = 0;
// Updates |view| with the information in |info|. Note that |view| is
// guaranteed to be a View returned from |CreateViewForNetwork()|.
virtual void UpdateViewForNetwork(views::View* view,
const NetworkInfo& info) = 0;
// Creates a Label to be displayed in the list to present some information
// (e.g. unavailability of network etc.).
virtual views::Label* CreateInfoLabel() = 0;
// Called when the user clicks on an entry representing a network in the list.
virtual void OnNetworkEntryClicked(views::View* sender) = 0;
// Called when the user clicks on a "Join Other" button.
virtual void OnOtherWifiClicked() = 0;
virtual void RelayoutScrollList() = 0;
};
} // namespace ash
#endif // ASH_SYSTEM_NETWORK_NETWORK_LIST_DELEGATE_H_
...@@ -4,9 +4,15 @@ ...@@ -4,9 +4,15 @@
#include "ash/system/network/network_list_view_base.h" #include "ash/system/network/network_list_view_base.h"
#include "base/logging.h"
namespace ash { namespace ash {
NetworkListViewBase::NetworkListViewBase() {} NetworkListViewBase::NetworkListViewBase(
tray::NetworkStateListDetailedView* detailed_view)
: detailed_view_(detailed_view) {
DCHECK(detailed_view_);
}
NetworkListViewBase::~NetworkListViewBase() {} NetworkListViewBase::~NetworkListViewBase() {}
......
...@@ -14,12 +14,14 @@ class View; ...@@ -14,12 +14,14 @@ class View;
} }
namespace ash { namespace ash {
namespace tray {
class NetworkStateListDetailedView;
}
// Base class for a list of available networks (and, in the case of VPNs, the // Base class for a list of available networks (and, in the case of VPNs, the
// list of available VPN providers). // list of available VPN providers).
class NetworkListViewBase { class NetworkListViewBase {
public: public:
NetworkListViewBase();
virtual ~NetworkListViewBase(); virtual ~NetworkListViewBase();
void set_container(views::View* container) { container_ = container; } void set_container(views::View* container) { container_ = container; }
...@@ -33,9 +35,18 @@ class NetworkListViewBase { ...@@ -33,9 +35,18 @@ class NetworkListViewBase {
virtual bool IsNetworkEntry(views::View* view, std::string* guid) const = 0; virtual bool IsNetworkEntry(views::View* view, std::string* guid) const = 0;
protected: protected:
views::View* container() { return container_; } explicit NetworkListViewBase(
tray::NetworkStateListDetailedView* detailed_view);
tray::NetworkStateListDetailedView* detailed_view() const {
return detailed_view_;
}
views::View* container() const { return container_; }
private: private:
tray::NetworkStateListDetailedView* const detailed_view_;
// The container that holds the actual list entries. // The container that holds the actual list entries.
views::View* container_ = nullptr; views::View* container_ = nullptr;
......
...@@ -17,19 +17,13 @@ ...@@ -17,19 +17,13 @@
#include "ash/strings/grit/ash_strings.h" #include "ash/strings/grit/ash_strings.h"
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "ash/system/network/network_icon_animation.h" #include "ash/system/network/network_icon_animation.h"
#include "ash/system/network/network_info.h"
#include "ash/system/network/network_list.h" #include "ash/system/network/network_list.h"
#include "ash/system/network/network_list_view_base.h" #include "ash/system/network/network_list_view_base.h"
#include "ash/system/network/tray_network_state_observer.h" #include "ash/system/network/tray_network_state_observer.h"
#include "ash/system/network/vpn_list_view.h" #include "ash/system/network/vpn_list_view.h"
#include "ash/system/networking_config_delegate.h"
#include "ash/system/tray/fixed_sized_image_view.h"
#include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_menu_button.h" #include "ash/system/tray/system_menu_button.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
#include "ash/system/tray/system_tray_controller.h" #include "ash/system/tray/system_tray_controller.h"
#include "ash/system/tray/system_tray_delegate.h"
#include "ash/system/tray/throbber_view.h"
#include "ash/system/tray/tray_constants.h" #include "ash/system/tray/tray_constants.h"
#include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_details_view.h"
#include "ash/system/tray/tray_popup_header_button.h" #include "ash/system/tray/tray_popup_header_button.h"
...@@ -79,30 +73,6 @@ namespace { ...@@ -79,30 +73,6 @@ namespace {
// Delay between scan requests. // Delay between scan requests.
const int kRequestScanDelaySeconds = 10; const int kRequestScanDelaySeconds = 10;
// TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc.
void SetupConnectedItem(HoverHighlightView* container,
const base::string16& text,
const gfx::ImageSkia& image) {
container->AddIconAndLabels(
image, text,
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTED));
TrayPopupItemStyle style(TrayPopupItemStyle::FontStyle::CAPTION);
style.set_color_style(TrayPopupItemStyle::ColorStyle::CONNECTED);
style.SetupLabel(container->sub_text_label());
}
// TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc.
void SetupConnectingItem(HoverHighlightView* container,
const base::string16& text,
const gfx::ImageSkia& image) {
container->AddIconAndLabels(
image, text,
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_NETWORK_STATUS_CONNECTING));
ThrobberView* throbber = new ThrobberView;
throbber->Start();
container->AddRightView(throbber);
}
} // namespace } // namespace
//------------------------------------------------------------------------------ //------------------------------------------------------------------------------
...@@ -445,32 +415,6 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() { ...@@ -445,32 +415,6 @@ views::View* NetworkStateListDetailedView::CreateNetworkInfoView() {
return label; return label;
} }
views::View* NetworkStateListDetailedView::CreateControlledByExtensionView(
const NetworkInfo& info) {
NetworkingConfigDelegate* networking_config_delegate =
Shell::Get()->system_tray_delegate()->GetNetworkingConfigDelegate();
if (!networking_config_delegate)
return nullptr;
std::unique_ptr<const NetworkingConfigDelegate::ExtensionInfo>
extension_info =
networking_config_delegate->LookUpExtensionForNetwork(info.guid);
if (!extension_info)
return nullptr;
// Get the tooltip text.
base::string16 tooltip_text = l10n_util::GetStringFUTF16(
IDS_ASH_STATUS_TRAY_EXTENSION_CONTROLLED_WIFI,
base::UTF8ToUTF16(extension_info->extension_name));
views::ImageView* controlled_icon =
new FixedSizedImageView(kTrayPopupDetailsIconWidth, 0);
controlled_icon->SetImage(
gfx::CreateVectorIcon(kCaptivePortalIcon, kMenuIconColor));
controlled_icon->SetTooltipText(tooltip_text);
return controlled_icon;
}
void NetworkStateListDetailedView::CallRequestScan() { void NetworkStateListDetailedView::CallRequestScan() {
VLOG(1) << "Requesting Network Scan."; VLOG(1) << "Requesting Network Scan.";
NetworkHandler::Get()->network_state_handler()->RequestScan(); NetworkHandler::Get()->network_state_handler()->RequestScan();
...@@ -481,64 +425,10 @@ void NetworkStateListDetailedView::CallRequestScan() { ...@@ -481,64 +425,10 @@ void NetworkStateListDetailedView::CallRequestScan() {
base::TimeDelta::FromSeconds(kRequestScanDelaySeconds)); base::TimeDelta::FromSeconds(kRequestScanDelaySeconds));
} }
views::View* NetworkStateListDetailedView::CreateViewForNetwork(
const NetworkInfo& info) {
HoverHighlightView* container = new HoverHighlightView(this);
if (info.connected)
SetupConnectedItem(container, info.label, info.image);
else if (info.connecting)
SetupConnectingItem(container, info.label, info.image);
else
container->AddIconAndLabel(info.image, info.label);
container->SetTooltipText(info.tooltip);
views::View* controlled_icon = CreateControlledByExtensionView(info);
if (controlled_icon)
container->AddChildView(controlled_icon);
return container;
}
NetworkTypePattern NetworkStateListDetailedView::GetNetworkTypePattern() const {
return list_type_ == LIST_TYPE_VPN ? NetworkTypePattern::VPN()
: NetworkTypePattern::NonVirtual();
}
void NetworkStateListDetailedView::UpdateViewForNetwork(
views::View* view,
const NetworkInfo& info) {
HoverHighlightView* container = static_cast<HoverHighlightView*>(view);
DCHECK(!container->has_children());
if (info.connected)
SetupConnectedItem(container, info.label, info.image);
else if (info.connecting)
SetupConnectingItem(container, info.label, info.image);
else
container->AddIconAndLabel(info.image, info.label);
views::View* controlled_icon = CreateControlledByExtensionView(info);
container->SetTooltipText(info.tooltip);
if (controlled_icon)
view->AddChildView(controlled_icon);
}
views::Label* NetworkStateListDetailedView::CreateInfoLabel() {
views::Label* label = new views::Label();
label->SetBorder(views::CreateEmptyBorder(kTrayPopupPaddingBetweenItems,
kTrayPopupPaddingHorizontal,
kTrayPopupPaddingBetweenItems, 0));
label->SetHorizontalAlignment(gfx::ALIGN_LEFT);
label->SetEnabledColor(SkColorSetARGB(192, 0, 0, 0));
return label;
}
void NetworkStateListDetailedView::OnNetworkEntryClicked(views::View* sender) { void NetworkStateListDetailedView::OnNetworkEntryClicked(views::View* sender) {
HandleViewClicked(sender); HandleViewClicked(sender);
} }
void NetworkStateListDetailedView::OnOtherWifiClicked() {
ShellPort::Get()->RecordUserMetricsAction(
UMA_STATUS_AREA_NETWORK_JOIN_OTHER_CLICKED);
Shell::Get()->system_tray_controller()->ShowNetworkCreate(shill::kTypeWifi);
}
void NetworkStateListDetailedView::RelayoutScrollList() { void NetworkStateListDetailedView::RelayoutScrollList() {
scroller()->Layout(); scroller()->Layout();
} }
......
...@@ -9,7 +9,6 @@ ...@@ -9,7 +9,6 @@
#include <string> #include <string>
#include "ash/login_status.h" #include "ash/login_status.h"
#include "ash/system/network/network_list_delegate.h"
#include "ash/system/tray/tray_details_view.h" #include "ash/system/tray/tray_details_view.h"
#include "base/macros.h" #include "base/macros.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
...@@ -17,10 +16,6 @@ ...@@ -17,10 +16,6 @@
#include "ui/views/controls/button/button.h" #include "ui/views/controls/button/button.h"
#include "ui/views/controls/button/custom_button.h" #include "ui/views/controls/button/custom_button.h"
namespace chromeos {
class NetworkTypePattern;
}
namespace ash { namespace ash {
class NetworkListViewBase; class NetworkListViewBase;
} }
...@@ -36,7 +31,6 @@ namespace tray { ...@@ -36,7 +31,6 @@ namespace tray {
class NetworkStateListDetailedView class NetworkStateListDetailedView
: public TrayDetailsView, : public TrayDetailsView,
public NetworkListDelegate,
public base::SupportsWeakPtr<NetworkStateListDetailedView> { public base::SupportsWeakPtr<NetworkStateListDetailedView> {
public: public:
enum ListType { LIST_TYPE_NETWORK, LIST_TYPE_VPN }; enum ListType { LIST_TYPE_NETWORK, LIST_TYPE_VPN };
...@@ -52,6 +46,11 @@ class NetworkStateListDetailedView ...@@ -52,6 +46,11 @@ class NetworkStateListDetailedView
// Manager properties (e.g. technology state) have changed. // Manager properties (e.g. technology state) have changed.
void Update(); void Update();
// Called when the user clicks on an entry representing a network in the list.
void OnNetworkEntryClicked(views::View* sender);
void RelayoutScrollList();
private: private:
class InfoBubble; class InfoBubble;
...@@ -74,24 +73,9 @@ class NetworkStateListDetailedView ...@@ -74,24 +73,9 @@ class NetworkStateListDetailedView
void OnInfoBubbleDestroyed(); void OnInfoBubbleDestroyed();
views::View* CreateNetworkInfoView(); views::View* CreateNetworkInfoView();
// Creates the view of an extra icon appearing next to the network name
// indicating that the network is controlled by an extension. If no extension
// is registered for this network, returns |nullptr|.
views::View* CreateControlledByExtensionView(const NetworkInfo& info);
// Periodically request a network scan. // Periodically request a network scan.
void CallRequestScan(); void CallRequestScan();
// NetworkListDelegate:
views::View* CreateViewForNetwork(const NetworkInfo& info) override;
chromeos::NetworkTypePattern GetNetworkTypePattern() const override;
void UpdateViewForNetwork(views::View* view,
const NetworkInfo& info) override;
views::Label* CreateInfoLabel() override;
void OnNetworkEntryClicked(views::View* sender) override;
void OnOtherWifiClicked() override;
void RelayoutScrollList() override;
// Type of list (all networks or vpn) // Type of list (all networks or vpn)
ListType list_type_; ListType list_type_;
......
...@@ -16,7 +16,7 @@ ...@@ -16,7 +16,7 @@
#include "ash/system/network/network_icon.h" #include "ash/system/network/network_icon.h"
#include "ash/system/network/network_icon_animation.h" #include "ash/system/network/network_icon_animation.h"
#include "ash/system/network/network_icon_animation_observer.h" #include "ash/system/network/network_icon_animation_observer.h"
#include "ash/system/network/network_list_delegate.h" #include "ash/system/network/network_state_list_detailed_view.h"
#include "ash/system/network/vpn_list.h" #include "ash/system/network/vpn_list.h"
#include "ash/system/tray/hover_highlight_view.h" #include "ash/system/tray/hover_highlight_view.h"
#include "ash/system/tray/system_menu_button.h" #include "ash/system/tray/system_menu_button.h"
...@@ -220,7 +220,8 @@ void VPNListNetworkEntry::UpdateFromNetworkState( ...@@ -220,7 +220,8 @@ void VPNListNetworkEntry::UpdateFromNetworkState(
Layout(); Layout();
} }
// TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. // TODO(varkha|mohsen): Consolidate with a similar method in
// BluetoothDetailedView. See https://crbug.com/686924.
void VPNListNetworkEntry::SetupConnectedItem(const base::string16& text, void VPNListNetworkEntry::SetupConnectedItem(const base::string16& text,
const gfx::ImageSkia& image) { const gfx::ImageSkia& image) {
AddIconAndLabels( AddIconAndLabels(
...@@ -231,7 +232,8 @@ void VPNListNetworkEntry::SetupConnectedItem(const base::string16& text, ...@@ -231,7 +232,8 @@ void VPNListNetworkEntry::SetupConnectedItem(const base::string16& text,
style.SetupLabel(sub_text_label()); style.SetupLabel(sub_text_label());
} }
// TODO(varkha): Consolidate with a similar method in tray_bluetooth.cc. // TODO(varkha|mohsen): Consolidate with a similar method in
// BluetoothDetailedView. See https://crbug.com/686924.
void VPNListNetworkEntry::SetupConnectingItem(const base::string16& text, void VPNListNetworkEntry::SetupConnectingItem(const base::string16& text,
const gfx::ImageSkia& image) { const gfx::ImageSkia& image) {
AddIconAndLabels( AddIconAndLabels(
...@@ -244,7 +246,8 @@ void VPNListNetworkEntry::SetupConnectingItem(const base::string16& text, ...@@ -244,7 +246,8 @@ void VPNListNetworkEntry::SetupConnectingItem(const base::string16& text,
} // namespace } // namespace
VPNListView::VPNListView(NetworkListDelegate* delegate) : delegate_(delegate) { VPNListView::VPNListView(tray::NetworkStateListDetailedView* detailed_view)
: NetworkListViewBase(detailed_view) {
Shell::Get()->vpn_list()->AddObserver(this); Shell::Get()->vpn_list()->AddObserver(this);
} }
...@@ -314,7 +317,7 @@ void VPNListView::Update() { ...@@ -314,7 +317,7 @@ void VPNListView::Update() {
// Layout the updated list. // Layout the updated list.
container()->SizeToPreferredSize(); container()->SizeToPreferredSize();
delegate_->RelayoutScrollList(); detailed_view()->RelayoutScrollList();
if (scroll_to_show_view) { if (scroll_to_show_view) {
// Scroll the list so that |scroll_to_show_view| is in view. // Scroll the list so that |scroll_to_show_view| is in view.
...@@ -357,7 +360,7 @@ void VPNListView::OnViewClicked(views::View* sender) { ...@@ -357,7 +360,7 @@ void VPNListView::OnViewClicked(views::View* sender) {
// If the user clicked on a network entry, let the |delegate_| trigger a // If the user clicked on a network entry, let the |delegate_| trigger a
// connection attempt (if the network is currently disconnected) or show a // connection attempt (if the network is currently disconnected) or show a
// configuration dialog (if the network is currently connected or connecting). // configuration dialog (if the network is currently connected or connecting).
delegate_->OnNetworkEntryClicked(sender); detailed_view()->OnNetworkEntryClicked(sender);
} }
void VPNListView::AddNetwork(const chromeos::NetworkState* network) { void VPNListView::AddNetwork(const chromeos::NetworkState* network) {
......
...@@ -18,15 +18,14 @@ namespace chromeos { ...@@ -18,15 +18,14 @@ namespace chromeos {
class NetworkState; class NetworkState;
} }
namespace ash {
class NetworkListDelegate;
}
namespace views { namespace views {
class View; class View;
} }
namespace ash { namespace ash {
namespace tray {
class NetworkStateListDetailedView;
}
// A list of VPN providers and networks that shows VPN providers and networks in // A list of VPN providers and networks that shows VPN providers and networks in
// a hierarchical layout, allowing the user to see at a glance which provider a // a hierarchical layout, allowing the user to see at a glance which provider a
...@@ -45,7 +44,7 @@ class VPNListView : public NetworkListViewBase, ...@@ -45,7 +44,7 @@ class VPNListView : public NetworkListViewBase,
public VpnList::Observer, public VpnList::Observer,
public ViewClickListener { public ViewClickListener {
public: public:
explicit VPNListView(NetworkListDelegate* delegate); explicit VPNListView(tray::NetworkStateListDetailedView* detailed_view);
~VPNListView() override; ~VPNListView() override;
// NetworkListViewBase: // NetworkListViewBase:
...@@ -72,8 +71,6 @@ class VPNListView : public NetworkListViewBase, ...@@ -72,8 +71,6 @@ class VPNListView : public NetworkListViewBase,
void AddProvidersAndNetworks( void AddProvidersAndNetworks(
const chromeos::NetworkStateHandler::NetworkStateList& networks); const chromeos::NetworkStateHandler::NetworkStateList& networks);
NetworkListDelegate* const delegate_;
// A mapping from each VPN provider's list entry to the provider. // A mapping from each VPN provider's list entry to the provider.
std::map<const views::View* const, VPNProvider> provider_view_map_; std::map<const views::View* const, VPNProvider> provider_view_map_;
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment