Commit 7dbdaebc authored by Scott Violet's avatar Scott Violet Committed by Commit Bot

chromeos: ensure there is active window when unblocking

SessionController may block windows (such as browser windows) from becoming
active. When trasitioning from blocking to not-blocking we should ensure there
is an active window. To do otherwise means there may be no active window,
which is a state we try to ensure doesn't exist.

BUG=914017
TEST=covered by tests

Change-Id: I5d9392ea7706ea3603ecc6f68201f4931ebfe642
Reviewed-on: https://chromium-review.googlesource.com/c/1372408Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Scott Violet <sky@chromium.org>
Cr-Commit-Position: refs/heads/master@{#615700}
parent e541d380
...@@ -37,6 +37,8 @@ ...@@ -37,6 +37,8 @@
#include "services/preferences/public/mojom/preferences.mojom.h" #include "services/preferences/public/mojom/preferences.mojom.h"
#include "services/service_manager/public/cpp/connector.h" #include "services/service_manager/public/cpp/connector.h"
#include "ui/message_center/message_center.h" #include "ui/message_center/message_center.h"
#include "ui/wm/core/focus_controller.h"
#include "ui/wm/core/focus_rules.h"
using session_manager::SessionState; using session_manager::SessionState;
...@@ -524,6 +526,7 @@ void SessionController::SetSessionState(SessionState state) { ...@@ -524,6 +526,7 @@ void SessionController::SetSessionState(SessionState state) {
if (state_ == state) if (state_ == state)
return; return;
const bool was_user_session_blocked = IsUserSessionBlocked();
const bool was_locked = state_ == SessionState::LOCKED; const bool was_locked = state_ == SessionState::LOCKED;
state_ = state; state_ = state;
for (auto& observer : observers_) for (auto& observer : observers_)
...@@ -547,6 +550,9 @@ void SessionController::SetSessionState(SessionState state) { ...@@ -547,6 +550,9 @@ void SessionController::SetSessionState(SessionState state) {
ConnectToSigninScreenPrefService(); ConnectToSigninScreenPrefService();
signin_screen_prefs_requested_ = true; signin_screen_prefs_requested_ = true;
} }
if (was_user_session_blocked && !IsUserSessionBlocked())
EnsureActiveWindowAfterUnblockingUserSession();
} }
void SessionController::AddUserSession(mojom::UserSessionPtr user_session) { void SessionController::AddUserSession(mojom::UserSessionPtr user_session) {
...@@ -730,4 +736,20 @@ void SessionController::MaybeNotifyOnActiveUserPrefServiceChanged() { ...@@ -730,4 +736,20 @@ void SessionController::MaybeNotifyOnActiveUserPrefServiceChanged() {
observer.OnActiveUserPrefServiceChanged(last_active_user_prefs_); observer.OnActiveUserPrefServiceChanged(last_active_user_prefs_);
} }
void SessionController::EnsureActiveWindowAfterUnblockingUserSession() {
if (!Shell::HasInstance())
return;
::wm::FocusController* focus_controller = Shell::Get()->focus_controller();
if (focus_controller->GetActiveWindow() ||
!Shell::GetRootWindowForNewWindows()) {
return;
}
aura::Window* to_activate =
Shell::Get()->focus_rules()->GetNextActivatableWindow(
Shell::GetRootWindowForNewWindows());
if (to_activate)
focus_controller->ActivateWindow(to_activate);
}
} // namespace ash } // namespace ash
...@@ -249,6 +249,10 @@ class ASH_EXPORT SessionController : public mojom::SessionController { ...@@ -249,6 +249,10 @@ class ASH_EXPORT SessionController : public mojom::SessionController {
// notification until that happens. // notification until that happens.
void MaybeNotifyOnActiveUserPrefServiceChanged(); void MaybeNotifyOnActiveUserPrefServiceChanged();
// Called when IsUserSessionBlocked() becomes true. If there isn't an active
// window, tries to activate one.
void EnsureActiveWindowAfterUnblockingUserSession();
// Bindings for users of the mojom::SessionController interface. // Bindings for users of the mojom::SessionController interface.
mojo::BindingSet<mojom::SessionController> bindings_; mojo::BindingSet<mojom::SessionController> bindings_;
......
...@@ -812,5 +812,20 @@ TEST_F(CanSwitchUserTest, OverviewModeDismissed) { ...@@ -812,5 +812,20 @@ TEST_F(CanSwitchUserTest, OverviewModeDismissed) {
EXPECT_EQ(1, switch_callback_hit_count()); EXPECT_EQ(1, switch_callback_hit_count());
} }
using SessionControllerUnblockTest = NoSessionAshTestBase;
TEST_F(SessionControllerUnblockTest, ActiveWindowAfterUnblocking) {
EXPECT_TRUE(Shell::Get()->session_controller()->IsUserSessionBlocked());
auto widget = CreateTestWidget();
// |widget| should not be active as it is blocked by SessionController.
EXPECT_FALSE(widget->IsActive());
SimulateUserLogin("user@test.com");
EXPECT_FALSE(Shell::Get()->session_controller()->IsUserSessionBlocked());
// |widget| should now be active as SessionController no longer is blocking
// windows from becoming active.
EXPECT_TRUE(widget->IsActive());
}
} // namespace } // namespace
} // namespace ash } // namespace ash
...@@ -905,6 +905,7 @@ Shell::~Shell() { ...@@ -905,6 +905,7 @@ Shell::~Shell() {
// Depends on |focus_controller_|, so must be destroyed before. // Depends on |focus_controller_|, so must be destroyed before.
window_tree_host_manager_.reset(); window_tree_host_manager_.reset();
focus_rules_ = nullptr;
focus_controller_.reset(); focus_controller_.reset();
screen_position_controller_.reset(); screen_position_controller_.reset();
...@@ -1063,8 +1064,8 @@ void Shell::Init( ...@@ -1063,8 +1064,8 @@ void Shell::Init(
AddPreTargetHandler(env_filter_.get()); AddPreTargetHandler(env_filter_.get());
// FocusController takes ownership of AshFocusRules. // FocusController takes ownership of AshFocusRules.
focus_controller_ = focus_rules_ = new wm::AshFocusRules();
std::make_unique<::wm::FocusController>(new wm::AshFocusRules()); focus_controller_ = std::make_unique<::wm::FocusController>(focus_rules_);
focus_controller_->AddObserver(this); focus_controller_->AddObserver(this);
window_selector_controller_ = std::make_unique<WindowSelectorController>(); window_selector_controller_ = std::make_unique<WindowSelectorController>();
......
...@@ -75,6 +75,7 @@ class AcceleratorFilter; ...@@ -75,6 +75,7 @@ class AcceleratorFilter;
class ActivationClient; class ActivationClient;
class CompoundEventFilter; class CompoundEventFilter;
class FocusController; class FocusController;
class FocusRules;
class ShadowController; class ShadowController;
class VisibilityController; class VisibilityController;
class WindowModalityController; class WindowModalityController;
...@@ -401,6 +402,7 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -401,6 +402,7 @@ class ASH_EXPORT Shell : public SessionObserver,
} }
FirstRunHelper* first_run_helper() { return first_run_helper_.get(); } FirstRunHelper* first_run_helper() { return first_run_helper_.get(); }
::wm::FocusController* focus_controller() { return focus_controller_.get(); } ::wm::FocusController* focus_controller() { return focus_controller_.get(); }
::wm::FocusRules* focus_rules() { return focus_rules_; }
FocusCycler* focus_cycler() { return focus_cycler_.get(); } FocusCycler* focus_cycler() { return focus_cycler_.get(); }
HighlighterController* highlighter_controller() { HighlighterController* highlighter_controller() {
return highlighter_controller_.get(); return highlighter_controller_.get();
...@@ -770,6 +772,8 @@ class ASH_EXPORT Shell : public SessionObserver, ...@@ -770,6 +772,8 @@ class ASH_EXPORT Shell : public SessionObserver,
std::unique_ptr<WallpaperController> wallpaper_controller_; std::unique_ptr<WallpaperController> wallpaper_controller_;
std::unique_ptr<WindowCycleController> window_cycle_controller_; std::unique_ptr<WindowCycleController> window_cycle_controller_;
std::unique_ptr<WindowSelectorController> window_selector_controller_; std::unique_ptr<WindowSelectorController> window_selector_controller_;
// Owned by |focus_controller_|.
::wm::FocusRules* focus_rules_ = nullptr;
std::unique_ptr<::wm::ShadowController> shadow_controller_; std::unique_ptr<::wm::ShadowController> shadow_controller_;
std::unique_ptr<::wm::VisibilityController> visibility_controller_; std::unique_ptr<::wm::VisibilityController> visibility_controller_;
std::unique_ptr<::wm::WindowModalityController> window_modality_controller_; std::unique_ptr<::wm::WindowModalityController> window_modality_controller_;
......
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