Commit a7dfbd28 authored by Tetsui Ohkubo's avatar Tetsui Ohkubo Committed by Commit Bot

Add VPN feature pod button.

This CL adds a feature pod button for VPN. By clicking on the button,
it will show VPN detailed view of the existing SystemTray.
This behavior is described as Development Stage 1 in the design doc:
go/cros-qs-restyling

Screenshot: http://screen/UGX2VC3yYpo

TEST=manual
BUG=813499

Change-Id: I5159f210279a92e8f17d5898050a7a678901fb86
Reviewed-on: https://chromium-review.googlesource.com/970003Reviewed-by: default avatarYoshiki Iguchi <yoshiki@chromium.org>
Commit-Queue: Tetsui Ohkubo <tetsui@chromium.org>
Cr-Commit-Position: refs/heads/master@{#544977}
parent 9a2f9c09
...@@ -579,6 +579,8 @@ component("ash") { ...@@ -579,6 +579,8 @@ component("ash") {
"system/network/tray_network_state_observer.h", "system/network/tray_network_state_observer.h",
"system/network/tray_vpn.cc", "system/network/tray_vpn.cc",
"system/network/tray_vpn.h", "system/network/tray_vpn.h",
"system/network/vpn_feature_pod_controller.cc",
"system/network/vpn_feature_pod_controller.h",
"system/network/vpn_list.cc", "system/network/vpn_list.cc",
"system/network/vpn_list.h", "system/network/vpn_list.h",
"system/network/vpn_list_view.cc", "system/network/vpn_list_view.cc",
......
...@@ -32,6 +32,37 @@ using chromeos::NetworkTypePattern; ...@@ -32,6 +32,37 @@ using chromeos::NetworkTypePattern;
namespace ash { namespace ash {
namespace tray { namespace tray {
bool IsVPNVisibleInSystemTray() {
LoginStatus login_status = Shell::Get()->session_controller()->login_status();
if (login_status == LoginStatus::NOT_LOGGED_IN)
return false;
// Show the VPN entry in the ash tray bubble if at least one third-party VPN
// provider is installed.
if (Shell::Get()->vpn_list()->HaveThirdPartyOrArcVPNProviders())
return true;
// Also show the VPN entry if at least one VPN network is configured.
NetworkStateHandler* const handler =
NetworkHandler::Get()->network_state_handler();
if (handler->FirstNetworkByType(NetworkTypePattern::VPN()))
return true;
return false;
}
bool IsVPNEnabled() {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
return handler->FirstNetworkByType(NetworkTypePattern::VPN());
}
bool IsVPNConnected() {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
const NetworkState* vpn =
handler->FirstNetworkByType(NetworkTypePattern::VPN());
return IsVPNEnabled() &&
(vpn->IsConnectedState() || vpn->IsConnectingState());
}
class VpnDefaultView : public TrayItemMore, class VpnDefaultView : public TrayItemMore,
public network_icon::AnimationObserver { public network_icon::AnimationObserver {
public: public:
...@@ -41,20 +72,6 @@ class VpnDefaultView : public TrayItemMore, ...@@ -41,20 +72,6 @@ class VpnDefaultView : public TrayItemMore,
network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this); network_icon::NetworkIconAnimation::GetInstance()->RemoveObserver(this);
} }
static bool ShouldShow() {
// Show the VPN entry in the ash tray bubble if at least one third-party VPN
// provider is installed.
if (Shell::Get()->vpn_list()->HaveThirdPartyOrArcVPNProviders())
return true;
// Also show the VPN entry if at least one VPN network is configured.
NetworkStateHandler* const handler =
NetworkHandler::Get()->network_state_handler();
if (handler->FirstNetworkByType(NetworkTypePattern::VPN()))
return true;
return false;
}
void Update() { void Update() {
gfx::ImageSkia image; gfx::ImageSkia image;
base::string16 label; base::string16 label;
...@@ -78,9 +95,9 @@ class VpnDefaultView : public TrayItemMore, ...@@ -78,9 +95,9 @@ class VpnDefaultView : public TrayItemMore,
std::unique_ptr<TrayPopupItemStyle> style = std::unique_ptr<TrayPopupItemStyle> style =
TrayItemMore::HandleCreateStyle(); TrayItemMore::HandleCreateStyle();
style->set_color_style( style->set_color_style(
!IsVpnEnabled() !IsVPNEnabled()
? TrayPopupItemStyle::ColorStyle::DISABLED ? TrayPopupItemStyle::ColorStyle::DISABLED
: IsVpnConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE : IsVPNConnected() ? TrayPopupItemStyle::ColorStyle::ACTIVE
: TrayPopupItemStyle::ColorStyle::INACTIVE); : TrayPopupItemStyle::ColorStyle::INACTIVE);
return style; return style;
} }
...@@ -91,21 +108,6 @@ class VpnDefaultView : public TrayItemMore, ...@@ -91,21 +108,6 @@ class VpnDefaultView : public TrayItemMore,
} }
private: private:
bool IsVpnEnabled() const {
NetworkStateHandler* handler =
NetworkHandler::Get()->network_state_handler();
return handler->FirstNetworkByType(NetworkTypePattern::VPN());
}
bool IsVpnConnected() const {
NetworkStateHandler* handler =
NetworkHandler::Get()->network_state_handler();
const NetworkState* vpn =
handler->FirstNetworkByType(NetworkTypePattern::VPN());
return IsVpnEnabled() &&
(vpn->IsConnectedState() || vpn->IsConnectingState());
}
void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image, void GetNetworkStateHandlerImageAndLabel(gfx::ImageSkia* image,
base::string16* label, base::string16* label,
bool* animating) { bool* animating) {
...@@ -118,7 +120,7 @@ class VpnDefaultView : public TrayItemMore, ...@@ -118,7 +120,7 @@ class VpnDefaultView : public TrayItemMore,
vpn && vpn->IsConnectedState() vpn && vpn->IsConnectedState()
? TrayPopupItemStyle::ColorStyle::ACTIVE ? TrayPopupItemStyle::ColorStyle::ACTIVE
: TrayPopupItemStyle::ColorStyle::INACTIVE)); : TrayPopupItemStyle::ColorStyle::INACTIVE));
if (!IsVpnConnected()) { if (!IsVPNConnected()) {
if (label) { if (label) {
*label = *label =
l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED); l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
...@@ -151,9 +153,7 @@ views::View* TrayVPN::CreateDefaultView(LoginStatus status) { ...@@ -151,9 +153,7 @@ views::View* TrayVPN::CreateDefaultView(LoginStatus status) {
CHECK(default_ == nullptr); CHECK(default_ == nullptr);
if (!chromeos::NetworkHandler::IsInitialized()) if (!chromeos::NetworkHandler::IsInitialized())
return nullptr; return nullptr;
if (status == LoginStatus::NOT_LOGGED_IN) if (!tray::IsVPNVisibleInSystemTray())
return nullptr;
if (!tray::VpnDefaultView::ShouldShow())
return nullptr; return nullptr;
const bool is_in_secondary_login_screen = const bool is_in_secondary_login_screen =
......
...@@ -17,7 +17,12 @@ class TrayNetworkStateObserver; ...@@ -17,7 +17,12 @@ class TrayNetworkStateObserver;
namespace tray { namespace tray {
class VPNListView; class VPNListView;
class VpnDefaultView; class VpnDefaultView;
}
extern bool IsVPNVisibleInSystemTray();
extern bool IsVPNEnabled();
extern bool IsVPNConnected();
} // namespace tray
class TrayVPN : public SystemTrayItem, class TrayVPN : public SystemTrayItem,
public TrayNetworkStateObserver::Delegate { public TrayNetworkStateObserver::Delegate {
......
// Copyright 2018 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.
#include "ash/system/network/vpn_feature_pod_controller.h"
#include "ash/resources/vector_icons/vector_icons.h"
#include "ash/session/session_controller.h"
#include "ash/shell.h"
#include "ash/strings/grit/ash_strings.h"
#include "ash/system/network/network_icon.h"
#include "ash/system/network/tray_vpn.h"
#include "ash/system/network/vpn_list.h"
#include "ash/system/tray/tray_constants.h"
#include "ash/system/unified/feature_pod_button.h"
#include "ash/system/unified/unified_system_tray_controller.h"
#include "chromeos/network/network_state.h"
#include "chromeos/network/network_state_handler.h"
#include "ui/base/l10n/l10n_util.h"
#include "ui/gfx/paint_vector_icon.h"
using chromeos::NetworkHandler;
using chromeos::NetworkState;
using chromeos::NetworkStateHandler;
using chromeos::NetworkTypePattern;
namespace ash {
namespace {
base::string16 GetNetworkStateHandlerLabel() {
NetworkStateHandler* handler = NetworkHandler::Get()->network_state_handler();
const NetworkState* vpn =
handler->FirstNetworkByType(NetworkTypePattern::VPN());
if (!tray::IsVPNConnected())
return l10n_util::GetStringUTF16(IDS_ASH_STATUS_TRAY_VPN_DISCONNECTED);
return network_icon::GetLabelForNetwork(vpn,
network_icon::ICON_TYPE_DEFAULT_VIEW);
}
} // namespace
VPNFeaturePodController::VPNFeaturePodController(
UnifiedSystemTrayController* tray_controller)
: tray_controller_(tray_controller) {}
VPNFeaturePodController::~VPNFeaturePodController() = default;
FeaturePodButton* VPNFeaturePodController::CreateButton() {
DCHECK(!button_);
button_ = new FeaturePodButton(this);
button_->SetVectorIcon(kNetworkVpnIcon);
Update();
return button_;
}
void VPNFeaturePodController::OnPressed() {
tray_controller_->ShowVPNDetailedView();
}
void VPNFeaturePodController::Update() {
button_->SetVisible(tray::IsVPNVisibleInSystemTray());
if (!button_->visible())
return;
button_->SetLabel(GetNetworkStateHandlerLabel());
button_->SetToggled(tray::IsVPNEnabled() && tray::IsVPNConnected());
}
} // namespace ash
// Copyright 2018 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_VPN_FEATURE_POD_CONTROLLER_H_
#define ASH_SYSTEM_NETWORK_VPN_FEATURE_POD_CONTROLLER_H_
#include "ash/system/unified/feature_pod_controller_base.h"
#include "base/macros.h"
#include "base/strings/string16.h"
namespace ash {
class UnifiedSystemTrayController;
// Controller of vpn feature pod button.
class VPNFeaturePodController : public FeaturePodControllerBase {
public:
VPNFeaturePodController(UnifiedSystemTrayController* tray_controller);
~VPNFeaturePodController() override;
// FeaturePodControllerBase:
FeaturePodButton* CreateButton() override;
void OnPressed() override;
private:
void Update();
// Unowned.
UnifiedSystemTrayController* const tray_controller_;
FeaturePodButton* button_ = nullptr;
DISALLOW_COPY_AND_ASSIGN(VPNFeaturePodController);
};
} // namespace ash
#endif // ASH_SYSTEM_NETWORK_VPN_FEATURE_POD_CONTROLLER_H_
...@@ -270,7 +270,8 @@ void SystemTray::CreateItems() { ...@@ -270,7 +270,8 @@ void SystemTray::CreateItems() {
std::make_unique<TrayPower>(this, message_center::MessageCenter::Get())); std::make_unique<TrayPower>(this, message_center::MessageCenter::Get()));
tray_network_ = new TrayNetwork(this); tray_network_ = new TrayNetwork(this);
AddTrayItem(base::WrapUnique(tray_network_)); AddTrayItem(base::WrapUnique(tray_network_));
AddTrayItem(std::make_unique<TrayVPN>(this)); tray_vpn_ = new TrayVPN(this);
AddTrayItem(base::WrapUnique(tray_vpn_));
tray_bluetooth_ = new TrayBluetooth(this); tray_bluetooth_ = new TrayBluetooth(this);
AddTrayItem(base::WrapUnique(tray_bluetooth_)); AddTrayItem(base::WrapUnique(tray_bluetooth_));
tray_cast_ = new TrayCast(this); tray_cast_ = new TrayCast(this);
...@@ -415,6 +416,10 @@ TrayAccessibility* SystemTray::GetTrayAccessibility() const { ...@@ -415,6 +416,10 @@ TrayAccessibility* SystemTray::GetTrayAccessibility() const {
return tray_accessibility_; return tray_accessibility_;
} }
TrayVPN* SystemTray::GetTrayVPN() const {
return tray_vpn_;
}
TrayIME* SystemTray::GetTrayIME() const { TrayIME* SystemTray::GetTrayIME() const {
return tray_ime_; return tray_ime_;
} }
......
...@@ -40,6 +40,7 @@ class TraySystemInfo; ...@@ -40,6 +40,7 @@ class TraySystemInfo;
class TrayTiles; class TrayTiles;
class TrayTracing; class TrayTracing;
class TrayUpdate; class TrayUpdate;
class TrayVPN;
class WebNotificationTray; class WebNotificationTray;
// There are different methods for creating bubble views. // There are different methods for creating bubble views.
...@@ -127,6 +128,8 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView { ...@@ -127,6 +128,8 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
TrayBluetooth* GetTrayBluetooth() const; TrayBluetooth* GetTrayBluetooth() const;
// Returns TrayAccessibility object if present or null otherwise. // Returns TrayAccessibility object if present or null otherwise.
TrayAccessibility* GetTrayAccessibility() const; TrayAccessibility* GetTrayAccessibility() const;
// Returns TrayVPN object if present or null otherwise.
TrayVPN* GetTrayVPN() const;
// Returns TrayIME object if present or null otherwise. // Returns TrayIME object if present or null otherwise.
TrayIME* GetTrayIME() const; TrayIME* GetTrayIME() const;
...@@ -230,6 +233,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView { ...@@ -230,6 +233,7 @@ class ASH_EXPORT SystemTray : public TrayBackgroundView {
TrayEnterprise* tray_enterprise_ = nullptr; TrayEnterprise* tray_enterprise_ = nullptr;
TrayIME* tray_ime_ = nullptr; TrayIME* tray_ime_ = nullptr;
TrayNetwork* tray_network_ = nullptr; TrayNetwork* tray_network_ = nullptr;
TrayVPN* tray_vpn_ = nullptr;
TrayTiles* tray_tiles_ = nullptr; TrayTiles* tray_tiles_ = nullptr;
TrayScale* tray_scale_ = nullptr; TrayScale* tray_scale_ = nullptr;
TraySessionLengthLimit* tray_session_length_limit_ = nullptr; TraySessionLengthLimit* tray_session_length_limit_ = nullptr;
......
...@@ -16,6 +16,8 @@ ...@@ -16,6 +16,8 @@
#include "ash/system/ime/tray_ime_chromeos.h" #include "ash/system/ime/tray_ime_chromeos.h"
#include "ash/system/network/network_feature_pod_controller.h" #include "ash/system/network/network_feature_pod_controller.h"
#include "ash/system/network/tray_network.h" #include "ash/system/network/tray_network.h"
#include "ash/system/network/tray_vpn.h"
#include "ash/system/network/vpn_feature_pod_controller.h"
#include "ash/system/night_light/night_light_feature_pod_controller.h" #include "ash/system/night_light/night_light_feature_pod_controller.h"
#include "ash/system/rotation/rotation_lock_feature_pod_controller.h" #include "ash/system/rotation/rotation_lock_feature_pod_controller.h"
#include "ash/system/tray/system_tray.h" #include "ash/system/tray/system_tray.h"
...@@ -81,45 +83,27 @@ void UnifiedSystemTrayController::ToggleExpanded() { ...@@ -81,45 +83,27 @@ void UnifiedSystemTrayController::ToggleExpanded() {
void UnifiedSystemTrayController::ShowNetworkDetailedView() { void UnifiedSystemTrayController::ShowNetworkDetailedView() {
// TODO(tetsui): Implement UnifiedSystemTray's Network detailed view. // TODO(tetsui): Implement UnifiedSystemTray's Network detailed view.
ShowSystemTrayDetailedView(system_tray_->GetTrayNetwork());
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayNetwork(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
} }
void UnifiedSystemTrayController::ShowBluetoothDetailedView() { void UnifiedSystemTrayController::ShowBluetoothDetailedView() {
// TODO(tetsui): Implement UnifiedSystemTray's Bluetooth detailed view. // TODO(tetsui): Implement UnifiedSystemTray's Bluetooth detailed view.
ShowSystemTrayDetailedView(system_tray_->GetTrayBluetooth());
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayBluetooth(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
} }
void UnifiedSystemTrayController::ShowAccessibilityDetailedView() { void UnifiedSystemTrayController::ShowAccessibilityDetailedView() {
// TODO(tetsui): Implement UnifiedSystemTray's Accessibility detailed view. // TODO(tetsui): Implement UnifiedSystemTray's Accessibility detailed view.
ShowSystemTrayDetailedView(system_tray_->GetTrayAccessibility());
}
// Initially create default view to set |default_bubble_height_|. void UnifiedSystemTrayController::ShowVPNDetailedView() {
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW, // TODO(tetsui): Implement UnifiedSystemTray's VPN detailed view.
true /* show_by_click */); ShowSystemTrayDetailedView(system_tray_->GetTrayVPN());
system_tray_->ShowDetailedView(system_tray_->GetTrayAccessibility(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
} }
void UnifiedSystemTrayController::ShowIMEDetailedView() { void UnifiedSystemTrayController::ShowIMEDetailedView() {
// TODO(tetsui): Implement UnifiedSystemTray's IME detailed view. // TODO(tetsui): Implement UnifiedSystemTray's IME detailed view.
// Initially create default view to set |default_bubble_height_|. ShowSystemTrayDetailedView(system_tray_->GetTrayIME());
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_->GetTrayIME(),
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
} }
void UnifiedSystemTrayController::InitFeaturePods() { void UnifiedSystemTrayController::InitFeaturePods() {
...@@ -129,6 +113,7 @@ void UnifiedSystemTrayController::InitFeaturePods() { ...@@ -129,6 +113,7 @@ void UnifiedSystemTrayController::InitFeaturePods() {
AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>()); AddFeaturePodItem(std::make_unique<RotationLockFeaturePodController>());
AddFeaturePodItem(std::make_unique<NightLightFeaturePodController>()); AddFeaturePodItem(std::make_unique<NightLightFeaturePodController>());
AddFeaturePodItem(std::make_unique<AccessibilityFeaturePodController>(this)); AddFeaturePodItem(std::make_unique<AccessibilityFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<VPNFeaturePodController>(this));
AddFeaturePodItem(std::make_unique<IMEFeaturePodController>(this)); AddFeaturePodItem(std::make_unique<IMEFeaturePodController>(this));
// If you want to add a new feature pod item, add here. // If you want to add a new feature pod item, add here.
...@@ -142,4 +127,14 @@ void UnifiedSystemTrayController::AddFeaturePodItem( ...@@ -142,4 +127,14 @@ void UnifiedSystemTrayController::AddFeaturePodItem(
feature_pod_controllers_.push_back(std::move(controller)); feature_pod_controllers_.push_back(std::move(controller));
} }
void UnifiedSystemTrayController::ShowSystemTrayDetailedView(
SystemTrayItem* system_tray_item) {
// Initially create default view to set |default_bubble_height_|.
system_tray_->ShowDefaultView(BubbleCreationType::BUBBLE_CREATE_NEW,
true /* show_by_click */);
system_tray_->ShowDetailedView(system_tray_item,
0 /* close_delay_in_seconds */,
BubbleCreationType::BUBBLE_USE_EXISTING);
}
} // namespace ash } // namespace ash
...@@ -15,6 +15,7 @@ namespace ash { ...@@ -15,6 +15,7 @@ namespace ash {
class FeaturePodControllerBase; class FeaturePodControllerBase;
class SystemTray; class SystemTray;
class SystemTrayItem;
class UnifiedBrightnessSliderController; class UnifiedBrightnessSliderController;
class UnifiedVolumeSliderController; class UnifiedVolumeSliderController;
class UnifiedSystemTrayView; class UnifiedSystemTrayView;
...@@ -47,6 +48,8 @@ class ASH_EXPORT UnifiedSystemTrayController { ...@@ -47,6 +48,8 @@ class ASH_EXPORT UnifiedSystemTrayController {
void ShowBluetoothDetailedView(); void ShowBluetoothDetailedView();
// Show the detailed view of accessibility. Called from the view. // Show the detailed view of accessibility. Called from the view.
void ShowAccessibilityDetailedView(); void ShowAccessibilityDetailedView();
// Show the detailed view of VPN. Called from the view.
void ShowVPNDetailedView();
// Show the detailed view of IME. Called from the view. // Show the detailed view of IME. Called from the view.
void ShowIMEDetailedView(); void ShowIMEDetailedView();
...@@ -58,6 +61,11 @@ class ASH_EXPORT UnifiedSystemTrayController { ...@@ -58,6 +61,11 @@ class ASH_EXPORT UnifiedSystemTrayController {
// Add the feature pod controller and its view. // Add the feature pod controller and its view.
void AddFeaturePodItem(std::unique_ptr<FeaturePodControllerBase> controller); void AddFeaturePodItem(std::unique_ptr<FeaturePodControllerBase> controller);
// Show detailed view of SystemTray.
// TODO(tetsui): Remove when detailed views are implemented on
// UnifiedSystemTray.
void ShowSystemTrayDetailedView(SystemTrayItem* system_tray_item);
// Only used to show detailed views which are still not implemented on // Only used to show detailed views which are still not implemented on
// UnifiedSystemTray. Unowned. // UnifiedSystemTray. Unowned.
// TODO(tetsui): Remove reference to |system_tray|. // TODO(tetsui): Remove reference to |system_tray|.
......
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