Commit 14f07c9f authored by Jazz Xu's avatar Jazz Xu Committed by Commit Bot

CrOS GMC: Hide global media controls when screen is locked.

Bug: 1131022
Change-Id: Ifb73b41adfee89dc72487dd5e34a061f188c93c3
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2423358Reviewed-by: default avatarTim Song <tengs@chromium.org>
Reviewed-by: default avatarTommy Steimel <steimel@chromium.org>
Reviewed-by: default avatarJenny Zhang <jennyz@chromium.org>
Commit-Queue: Jazz Xu <jazzhsu@chromium.org>
Cr-Commit-Position: refs/heads/master@{#809685}
parent 3a0b993e
......@@ -65,6 +65,8 @@ MediaTray::MediaTray(Shelf* shelf) : TrayBackgroundView(shelf) {
if (MediaNotificationProvider::Get())
MediaNotificationProvider::Get()->AddObserver(this);
Shell::Get()->session_controller()->AddObserver(this);
auto icon = std::make_unique<views::ImageView>();
icon->SetTooltipText(l10n_util::GetStringUTF16(
IDS_ASH_GLOBAL_MEDIA_CONTROLS_BUTTON_TOOLTIP_TEXT));
......@@ -82,6 +84,8 @@ MediaTray::~MediaTray() {
if (MediaNotificationProvider::Get())
MediaNotificationProvider::Get()->RemoveObserver(this);
Shell::Get()->session_controller()->RemoveObserver(this);
}
void MediaTray::OnNotificationListChanged() {
......@@ -171,13 +175,18 @@ void MediaTray::ClickedOutsideBubble() {
CloseBubble();
}
void MediaTray::OnLockStateChanged(bool locked) {
UpdateDisplayState();
}
void MediaTray::UpdateDisplayState() {
if (!MediaNotificationProvider::Get())
return;
bool should_show =
MediaNotificationProvider::Get()->HasActiveNotifications() ||
MediaNotificationProvider::Get()->HasFrozenNotifications();
(MediaNotificationProvider::Get()->HasActiveNotifications() ||
MediaNotificationProvider::Get()->HasFrozenNotifications()) &&
!Shell::Get()->session_controller()->IsScreenLocked();
if (!should_show && bubble_)
CloseBubble();
......
......@@ -6,6 +6,7 @@
#define ASH_SYSTEM_MEDIA_MEDIA_TRAY_H_
#include "ash/public/cpp/media_notification_provider_observer.h"
#include "ash/public/cpp/session/session_observer.h"
#include "ash/system/tray/tray_background_view.h"
namespace views {
......@@ -18,7 +19,8 @@ class Shelf;
class TrayBubbleWrapper;
class MediaTray : public MediaNotificationProviderObserver,
public TrayBackgroundView {
public TrayBackgroundView,
public SessionObserver {
public:
explicit MediaTray(Shelf* shelf);
~MediaTray() override;
......@@ -37,6 +39,9 @@ class MediaTray : public MediaNotificationProviderObserver,
void HideBubbleWithView(const TrayBubbleView* bubble_view) override;
void ClickedOutsideBubble() override;
// SessionObserver implementation.
void OnLockStateChanged(bool locked) override;
TrayBubbleWrapper* tray_bubble_wrapper_for_testing() { return bubble_.get(); }
private:
......
......@@ -28,6 +28,10 @@ class MockMediaNotificationProvider : public MediaNotificationProvider {
[](auto, auto) { return std::make_unique<views::View>(); });
}
~MockMediaNotificationProvider() override {
MediaNotificationProvider::Set(nullptr);
}
// Medianotificationprovider implementations.
MOCK_METHOD2(GetMediaNotificationListView,
std::unique_ptr<views::View>(SkColor, int));
......@@ -111,6 +115,15 @@ TEST_F(MediaTrayTest, MediaTrayVisibilityTest) {
provider()->SetHasFrozenNotifications(true);
SimulateNotificationListChanged();
EXPECT_TRUE(media_tray()->GetVisible());
// Media tray should be hidden when screen is locked.
GetSessionControllerClient()->LockScreen();
GetSessionControllerClient()->FlushForTest();
EXPECT_FALSE(media_tray()->GetVisible());
// Media tray should be visible again when we unlock the screen.
GetSessionControllerClient()->UnlockScreen();
EXPECT_TRUE(media_tray()->GetVisible());
}
TEST_F(MediaTrayTest, ShowAndHideBubbleTest) {
......
......@@ -133,7 +133,8 @@ UnifiedSystemTrayView* UnifiedSystemTrayController::CreateView() {
unified_view_ = new UnifiedSystemTrayView(this, model_->IsExpandedOnOpen());
InitFeaturePods();
if (base::FeatureList::IsEnabled(media::kGlobalMediaControlsForChromeOS)) {
if (base::FeatureList::IsEnabled(media::kGlobalMediaControlsForChromeOS) &&
!Shell::Get()->session_controller()->IsScreenLocked()) {
media_controls_controller_ =
std::make_unique<UnifiedMediaControlsController>(this);
unified_view_->AddMediaControlsView(
......
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