Commit fa0ab3e4 authored by Sarah Hu's avatar Sarah Hu Committed by Commit Bot

cros: Update visibility of guest and apps button in the shelf.

Bug: 857514
Cq-Include-Trybots: luci.chromium.try:closure_compilation
Change-Id: I6ca7211bcf811b57fb03f5fe275c6c2600e654ee
Reviewed-on: https://chromium-review.googlesource.com/1142384Reviewed-by: default avatarAga Wronska <agawronska@chromium.org>
Reviewed-by: default avatarJacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarTom Sepez <tsepez@chromium.org>
Reviewed-by: default avatarMichael Wasserman <msw@chromium.org>
Commit-Queue: Xiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#577977}
parent 5334e9c4
......@@ -315,16 +315,11 @@ void LoginScreenController::SetAuthType(
}
}
void LoginScreenController::LoadUsers(
std::vector<mojom::LoginUserInfoPtr> users,
bool show_guest) {
void LoginScreenController::SetUserList(
std::vector<mojom::LoginUserInfoPtr> users) {
DCHECK(DataDispatcher());
DataDispatcher()->NotifyUsers(users);
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->login_shelf_view()
->SetAllowLoginAsGuest(show_guest);
}
void LoginScreenController::SetPinEnabledForUser(const AccountId& account_id,
......@@ -414,11 +409,19 @@ void LoginScreenController::SetKioskApps(
->SetKioskApps(std::move(kiosk_apps));
}
void LoginScreenController::NotifyOobeDialogVisibility(bool visible) {
void LoginScreenController::NotifyOobeDialogState(
mojom::OobeDialogState state) {
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->login_shelf_view()
->SetLoginDialogState(state);
}
void LoginScreenController::SetAllowLoginAsGuest(bool allow_guest) {
Shelf::ForWindow(Shell::Get()->GetPrimaryRootWindow())
->shelf_widget()
->login_shelf_view()
->SetLoginDialogVisible(visible);
->SetAllowLoginAsGuest(allow_guest);
}
void LoginScreenController::SetAddUserButtonEnabled(bool enable) {
......
......@@ -111,8 +111,7 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen {
void SetAuthType(const AccountId& account_id,
proximity_auth::mojom::AuthType auth_type,
const base::string16& initial_value) override;
void LoadUsers(std::vector<mojom::LoginUserInfoPtr> users,
bool show_guest) override;
void SetUserList(std::vector<mojom::LoginUserInfoPtr> users) override;
void SetPinEnabledForUser(const AccountId& account_id,
bool is_enabled) override;
void SetAvatarForUser(const AccountId& account_id,
......@@ -139,8 +138,9 @@ class ASH_EXPORT LoginScreenController : public mojom::LoginScreen {
void SetFingerprintUnlockState(const AccountId& account_id,
mojom::FingerprintUnlockState state) override;
void SetKioskApps(std::vector<mojom::KioskAppInfoPtr> kiosk_apps) override;
void NotifyOobeDialogVisibility(bool is_visible) override;
void NotifyOobeDialogState(mojom::OobeDialogState state) override;
void SetAddUserButtonEnabled(bool enable) override;
void SetAllowLoginAsGuest(bool allow_guest) override;
// Flushes the mojo pipes - to be used in tests.
void FlushForTesting();
......
......@@ -12,6 +12,33 @@ import "components/account_id/interfaces/account_id.mojom";
import "mojo/public/mojom/base/string16.mojom";
import "mojo/public/mojom/base/time.mojom";
// State of the Oobe UI dialog.
enum OobeDialogState {
// Oobe UI dialog is currently hidden.
HIDDEN,
// Showing gaia signin screen.
GAIA_SIGNIN,
// Showing wrong hardware identification screen.
WRONG_HWID_WARNING,
// Showing supervised user creation screen.
SUPERVISED_USER_CREATION_FLOW,
// Showing SAML password confirmation screen.
SAML_PASSWORD_CONFIRM,
// Showing password changed screen.
PASSWORD_CHANGED,
// Showing device enrollment screen.
ENROLLMENT,
// Showing error screen.
ERROR,
};
// Allows clients (e.g. Chrome browser) to control the ash login/lock/user-add
// screens.
interface LoginScreen {
......@@ -59,10 +86,9 @@ interface LoginScreen {
proximity_auth.mojom.AuthType auth_type,
mojo_base.mojom.String16 initial_value);
// Requests to load users in the lock screen.
// |users|: A list of users who can unlock the device.
// |show_guest|: Whether to show guest session button.
LoadUsers(array<LoginUserInfo> users, bool show_guest);
// Set the users who are displayed on the login UI. |users| is filtered
// and does not correspond to every user on the device.
SetUserList(array<LoginUserInfo> users);
// Notification if pin is enabled or disabled for the given user.
// |account_id|: The account id of the user in the user pod.
......@@ -130,13 +156,17 @@ interface LoginScreen {
// Update the kiosk app data for the login screen.
SetKioskApps(array<KioskAppInfo> kiosk_apps);
// Called when the dialog hosting oobe has changed visibility. The oobe dialog
// Called when the dialog hosting oobe has changed state. The oobe dialog
// provides support for any part of login that is implemented in JS/HTML, such
// as add user or powerwash.
NotifyOobeDialogVisibility(bool is_visible);
NotifyOobeDialogState(OobeDialogState state);
// Sets whether users can be added from the login screen.
SetAddUserButtonEnabled(bool enable);
// Sets if the guest button on the login shelf can be shown. Even if set to
// true the button may still not be visible.
SetAllowLoginAsGuest(bool allow_guest);
};
// Allows ash lock screen to control a client (e.g. Chrome browser). Requests
......
......@@ -410,8 +410,8 @@ void LoginShelfView::SetKioskApps(
UpdateUi();
}
void LoginShelfView::SetLoginDialogVisible(bool visible) {
dialog_visible_ = visible;
void LoginShelfView::SetLoginDialogState(mojom::OobeDialogState state) {
dialog_state_ = state;
UpdateUi();
}
......@@ -478,12 +478,33 @@ void LoginShelfView::UpdateUi() {
// TODO(agawronska): Implement full list of conditions for buttons visibility,
// when views based shelf if enabled during OOBE. https://crbug.com/798869
bool is_login_primary = (session_state == SessionState::LOGIN_PRIMARY);
bool dialog_visible = dialog_state_ != mojom::OobeDialogState::HIDDEN;
// Show guest button if:
// 1. It's in login screen.
// 2. Guest login is allowed.
// 3. OOBE UI dialog is not currently showing wrong HWID warning screen or
// SAML password confirmation screen.
GetViewByID(kBrowseAsGuest)
->SetVisible(allow_guest_ && !dialog_visible_ && is_login_primary);
GetViewByID(kAddUser)->SetVisible(!dialog_visible_ && is_login_primary);
->SetVisible(
allow_guest_ &&
dialog_state_ != mojom::OobeDialogState::WRONG_HWID_WARNING &&
dialog_state_ != mojom::OobeDialogState::SAML_PASSWORD_CONFIRM &&
is_login_primary);
// Show add user button when it's in login screen and OobeUI dialog is not
// visible.
GetViewByID(kAddUser)->SetVisible(!dialog_visible && is_login_primary);
// Show kiosk apps button if:
// 1. It's in login screen.
// 2. There're Kiosk apps availble.
// 3. Oobe UI dialog is not visible or is currently showing gaia signin
// screen.
kiosk_apps_button_->SetVisible(
!dialog_visible_ && kiosk_apps_button_->HasApps() && is_login_primary);
(!dialog_visible ||
dialog_state_ == mojom::OobeDialogState::GAIA_SIGNIN) &&
kiosk_apps_button_->HasApps() && is_login_primary);
Layout();
}
......
......@@ -10,6 +10,7 @@
#include "ash/ash_export.h"
#include "ash/lock_screen_action/lock_screen_action_background_observer.h"
#include "ash/public/interfaces/kiosk_app_info.mojom.h"
#include "ash/public/interfaces/login_screen.mojom.h"
#include "ash/shutdown_controller.h"
#include "ash/tray_action/tray_action_observer.h"
#include "base/scoped_observer.h"
......@@ -63,9 +64,8 @@ class ASH_EXPORT LoginShelfView : public views::View,
// Sets the list of kiosk apps that can be launched from the login shelf.
void SetKioskApps(std::vector<mojom::KioskAppInfoPtr> kiosk_apps);
// Sets if the login dialog is visible. This hides some of the buttons on the
// LoginShelf.
void SetLoginDialogVisible(bool visible);
// Sets the state of the login dialog.
void SetLoginDialogState(mojom::OobeDialogState state);
// Sets if the guest button on the login shelf can be shown. Even if set to
// true the button may still not be visible.
......@@ -101,7 +101,7 @@ class ASH_EXPORT LoginShelfView : public views::View,
// policy updates, session state changes etc.
void UpdateUi();
bool dialog_visible_ = false;
mojom::OobeDialogState dialog_state_ = mojom::OobeDialogState::HIDDEN;
bool allow_guest_ = true;
LockScreenActionBackgroundController* lock_screen_action_background_;
......
......@@ -291,23 +291,68 @@ TEST_F(LoginShelfViewTest, SetAllowLoginByGuest) {
// However, SetAllowLoginAsGuest(true) does not mean that the guest button is
// always visible.
login_shelf_view_->SetLoginDialogVisible(true);
login_shelf_view_->SetLoginDialogState(
mojom::OobeDialogState::SAML_PASSWORD_CONFIRM);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown}));
}
TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterDialogVisibilityChange) {
TEST_F(LoginShelfViewTest, ShouldUpdateUiAfterDialogStateChange) {
NotifySessionStateChanged(SessionState::LOGIN_PRIMARY);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown,
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
login_shelf_view_->SetLoginDialogVisible(true);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown}));
// Add user button is always hidden if dialog state !=
// OobeDialogState::HIDDEN.
login_shelf_view_->SetLoginDialogState(mojom::OobeDialogState::GAIA_SIGNIN);
EXPECT_TRUE(ShowsShelfButtons(
{LoginShelfView::kShutdown, LoginShelfView::kBrowseAsGuest}));
login_shelf_view_->SetLoginDialogVisible(false);
login_shelf_view_->SetLoginDialogState(mojom::OobeDialogState::HIDDEN);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown,
LoginShelfView::kBrowseAsGuest,
LoginShelfView::kAddUser}));
// Guest button is hidden if dialog state ==
// OobeDialogState::WRONG_HWID_WARNING or SAML_PASSWORD_CONFIRM.
login_shelf_view_->SetLoginDialogState(
mojom::OobeDialogState::WRONG_HWID_WARNING);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown}));
login_shelf_view_->SetLoginDialogState(
mojom::OobeDialogState::SAML_PASSWORD_CONFIRM);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown}));
login_shelf_view_->SetLoginDialogState(mojom::OobeDialogState::GAIA_SIGNIN);
EXPECT_TRUE(ShowsShelfButtons(
{LoginShelfView::kShutdown, LoginShelfView::kBrowseAsGuest}));
// Guest button is hidden if SetAllowLoginAsGuest(false).
login_shelf_view_->SetAllowLoginAsGuest(false /*allow_guest*/);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown}));
// Kiosk app button is visible when dialog state == OobeDialogState::HIDDEN
// or GAIA_SIGNIN.
login_shelf_view_->SetLoginDialogState(mojom::OobeDialogState::GAIA_SIGNIN);
std::vector<mojom::KioskAppInfoPtr> kiosk_apps;
kiosk_apps.push_back(mojom::KioskAppInfo::New());
login_shelf_view_->SetKioskApps(std::move(kiosk_apps));
EXPECT_TRUE(
ShowsShelfButtons({LoginShelfView::kShutdown, LoginShelfView::kApps}));
login_shelf_view_->SetLoginDialogState(
mojom::OobeDialogState::SAML_PASSWORD_CONFIRM);
EXPECT_TRUE(ShowsShelfButtons({LoginShelfView::kShutdown}));
login_shelf_view_->SetLoginDialogState(mojom::OobeDialogState::HIDDEN);
EXPECT_TRUE(
ShowsShelfButtons({LoginShelfView::kShutdown, LoginShelfView::kAddUser,
LoginShelfView::kApps}));
// Kiosk app button is hidden when no app exists.
login_shelf_view_->SetKioskApps(std::vector<mojom::KioskAppInfoPtr>());
EXPECT_TRUE(
ShowsShelfButtons({LoginShelfView::kShutdown, LoginShelfView::kAddUser}));
}
TEST_F(LoginShelfViewTest, ClickShutdownButton) {
......
......@@ -81,9 +81,10 @@ ViewsScreenLocker::~ViewsScreenLocker() {
void ViewsScreenLocker::Init() {
lock_time_ = base::TimeTicks::Now();
user_selection_screen_->Init(screen_locker_->users());
LoginScreenClient::Get()->login_screen()->LoadUsers(
user_selection_screen_->UpdateAndReturnUserListForMojo(),
false /* show_guests */);
LoginScreenClient::Get()->login_screen()->SetUserList(
user_selection_screen_->UpdateAndReturnUserListForMojo());
LoginScreenClient::Get()->login_screen()->SetAllowLoginAsGuest(
false /*show_guest*/);
if (!ime_state_.get())
ime_state_ = input_method::InputMethodManager::Get()->GetActiveIMEState();
......
......@@ -74,8 +74,9 @@ void LoginDisplayMojo::Init(const user_manager::UserList& filtered_users,
UserSelectionScreen* user_selection_screen = host_->user_selection_screen();
user_selection_screen->Init(filtered_users);
client->login_screen()->LoadUsers(
user_selection_screen->UpdateAndReturnUserListForMojo(), show_guest);
client->login_screen()->SetUserList(
user_selection_screen->UpdateAndReturnUserListForMojo());
client->login_screen()->SetAllowLoginAsGuest(show_guest);
user_selection_screen->SetUsersLoaded(true /*loaded*/);
// Enable pin for any users who can use it.
......
......@@ -5,6 +5,7 @@
#include "chrome/browser/chromeos/login/ui/oobe_ui_dialog_delegate.h"
#include "ash/public/cpp/shell_window_ids.h"
#include "ash/public/interfaces/login_screen.mojom.h"
#include "chrome/browser/chromeos/login/screens/gaia_view.h"
#include "chrome/browser/chromeos/login/ui/login_display_host_mojo.h"
#include "chrome/browser/chromeos/profiles/profile_helper.h"
......@@ -84,7 +85,8 @@ content::WebContents* OobeUIDialogDelegate::GetWebContents() {
}
void OobeUIDialogDelegate::Show() {
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogVisibility(true);
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogState(
ash::mojom::OobeDialogState::GAIA_SIGNIN);
dialog_widget_->Show();
}
......@@ -101,14 +103,16 @@ void OobeUIDialogDelegate::ShowFullScreen() {
void OobeUIDialogDelegate::Hide() {
if (!dialog_widget_)
return;
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogVisibility(false);
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogState(
ash::mojom::OobeDialogState::HIDDEN);
dialog_widget_->Hide();
}
void OobeUIDialogDelegate::Close() {
if (!dialog_widget_)
return;
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogVisibility(false);
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogState(
ash::mojom::OobeDialogState::HIDDEN);
dialog_widget_->Close();
}
......
......@@ -301,6 +301,9 @@ cr.define('login', function() {
set signinUIState(state) {
this.signinUIState_ = state;
this.updateUI_();
if (Oobe.getInstance().showingViewsLogin)
chrome.send('updateSigninUIState', [state]);
},
/**
......
......@@ -706,6 +706,11 @@ login.createScreen('GaiaSigninScreen', 'gaia-signin', function() {
$('login-header-bar').showCreateSupervisedButton =
data.supervisedUsersCanCreate;
$('login-header-bar').showGuestButton = data.guestSignin;
if (Oobe.getInstance().showingViewsLogin) {
chrome.send(
'showGuestButton',
[data.guestSignin && !this.closable && this.isAtTheBeginning()]);
}
// Reset SAML
this.classList.toggle('full-width', false);
......
......@@ -40,6 +40,7 @@
#include "chrome/browser/lifetime/browser_shutdown.h"
#include "chrome/browser/net/system_network_context_manager.h"
#include "chrome/browser/profiles/profile.h"
#include "chrome/browser/ui/ash/login_screen_client.h"
#include "chrome/browser/ui/webui/chromeos/login/active_directory_password_change_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/enrollment_screen_handler.h"
#include "chrome/browser/ui/webui/chromeos/login/signin_screen_handler.h"
......@@ -579,6 +580,9 @@ void GaiaScreenHandler::RegisterMessages() {
AddCallback("updateOobeDialogSize",
&GaiaScreenHandler::HandleUpdateOobeDialogSize);
AddCallback("hideOobeDialog", &GaiaScreenHandler::HandleHideOobeDialog);
AddCallback("updateSigninUIState",
&GaiaScreenHandler::HandleUpdateSigninUIState);
AddCallback("showGuestButton", &GaiaScreenHandler::HandleShowGuestButton);
// Allow UMA metrics collection from JS.
web_ui()->AddMessageHandler(std::make_unique<MetricsHandler>());
......@@ -852,6 +856,26 @@ void GaiaScreenHandler::HandleGetIsSamlUserPasswordless(
base::Value(false) /* isSamlUserPasswordless */);
}
void GaiaScreenHandler::HandleUpdateSigninUIState(int state) {
if (!ash::features::IsViewsLoginEnabled() ||
!LoginScreenClient::HasInstance()) {
return;
}
auto dialog_state = static_cast<ash::mojom::OobeDialogState>(state);
DCHECK(ash::mojom::IsKnownEnumValue(dialog_state));
LoginScreenClient::Get()->login_screen()->NotifyOobeDialogState(dialog_state);
}
void GaiaScreenHandler::HandleShowGuestButton(bool show) {
if (!ash::features::IsViewsLoginEnabled() ||
!LoginScreenClient::HasInstance()) {
return;
}
LoginScreenClient::Get()->login_screen()->SetAllowLoginAsGuest(show);
}
void GaiaScreenHandler::OnShowAddUser() {
signin_screen_handler_->is_account_picker_showing_first_time_ = false;
lock_screen_utils::EnforcePolicyInputMethods(std::string());
......
......@@ -137,6 +137,9 @@ class GaiaScreenHandler : public BaseScreenHandler,
void HandleGetIsSamlUserPasswordless(const std::string& callback_id,
const std::string& typed_email,
const std::string& gaia_id);
void HandleUpdateSigninUIState(int state);
void HandleShowGuestButton(bool show);
void OnShowAddUser();
// Really handles the complete login message.
......
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