Commit 21cd5663 authored by Jacob Dufault's avatar Jacob Dufault Committed by Commit Bot

cros: Do not allow password submit on empty password.

Tap to unlock still should work on an empty password, though.

Bug: 839320
Change-Id: Id5fd17c9428ddc2b6823cd3c63a5f21aa486b860
Reviewed-on: https://chromium-review.googlesource.com/1164257
Commit-Queue: Jacob Dufault <jdufault@chromium.org>
Reviewed-by: default avatarXiaoyin Hu <xiaoyinh@chromium.org>
Cr-Commit-Position: refs/heads/master@{#581278}
parent 460c4724
...@@ -306,8 +306,8 @@ void LoginScreenController::SetAuthType( ...@@ -306,8 +306,8 @@ void LoginScreenController::SetAuthType(
proximity_auth::mojom::AuthType auth_type, proximity_auth::mojom::AuthType auth_type,
const base::string16& initial_value) { const base::string16& initial_value) {
if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) { if (auth_type == proximity_auth::mojom::AuthType::USER_CLICK) {
DataDispatcher()->SetClickToUnlockEnabledForUser(account_id, DataDispatcher()->SetTapToUnlockEnabledForUser(account_id,
true /*enabled*/); true /*enabled*/);
} else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) { } else if (auth_type == proximity_auth::mojom::AuthType::ONLINE_SIGN_IN) {
DataDispatcher()->SetForceOnlineSignInForUser(account_id); DataDispatcher()->SetForceOnlineSignInForUser(account_id);
} else { } else {
......
...@@ -636,9 +636,8 @@ void LockContentsView::OnAuthEnabledForUserChanged( ...@@ -636,9 +636,8 @@ void LockContentsView::OnAuthEnabledForUserChanged(
} }
} }
void LockContentsView::OnClickToUnlockEnabledForUserChanged( void LockContentsView::OnTapToUnlockEnabledForUserChanged(const AccountId& user,
const AccountId& user, bool enabled) {
bool enabled) {
LockContentsView::UserState* state = FindStateForUser(user); LockContentsView::UserState* state = FindStateForUser(user);
if (!state) { if (!state) {
LOG(ERROR) << "Unable to find user enabling click to auth"; LOG(ERROR) << "Unable to find user enabling click to auth";
...@@ -1422,7 +1421,7 @@ void LockContentsView::OnEasyUnlockIconTapped() { ...@@ -1422,7 +1421,7 @@ void LockContentsView::OnEasyUnlockIconTapped() {
CurrentBigUserView()->GetCurrentUser()->basic_user_info->account_id; CurrentBigUserView()->GetCurrentUser()->basic_user_info->account_id;
Shell::Get()->login_screen_controller()->HardlockPod(user); Shell::Get()->login_screen_controller()->HardlockPod(user);
// TODO(jdufault): This should get called as a result of HardlockPod. // TODO(jdufault): This should get called as a result of HardlockPod.
OnClickToUnlockEnabledForUserChanged(user, false /*enabled*/); OnTapToUnlockEnabledForUserChanged(user, false /*enabled*/);
} }
} }
......
...@@ -145,8 +145,8 @@ class ASH_EXPORT LockContentsView ...@@ -145,8 +145,8 @@ class ASH_EXPORT LockContentsView
bool enabled, bool enabled,
const base::Optional<base::Time>& auth_reenabled_time) override; const base::Optional<base::Time>& auth_reenabled_time) override;
void OnLockScreenNoteStateChanged(mojom::TrayActionState state) override; void OnLockScreenNoteStateChanged(mojom::TrayActionState state) override;
void OnClickToUnlockEnabledForUserChanged(const AccountId& user, void OnTapToUnlockEnabledForUserChanged(const AccountId& user,
bool enabled) override; bool enabled) override;
void OnForceOnlineSignInForUser(const AccountId& user) override; void OnForceOnlineSignInForUser(const AccountId& user) override;
void OnShowEasyUnlockIcon( void OnShowEasyUnlockIcon(
const AccountId& user, const AccountId& user,
......
...@@ -51,6 +51,7 @@ enum { ...@@ -51,6 +51,7 @@ enum {
kGlobalCycleDetachableBaseId, kGlobalCycleDetachableBaseId,
kGlobalCycleAuthErrorMessage, kGlobalCycleAuthErrorMessage,
kPerUserTogglePin, kPerUserTogglePin,
kPerUserToggleTap,
kPerUserCycleEasyUnlockState, kPerUserCycleEasyUnlockState,
kPerUserCycleFingerprintState, kPerUserCycleFingerprintState,
kPerUserForceOnlineSignIn, kPerUserForceOnlineSignIn,
...@@ -94,7 +95,7 @@ struct UserMetadata { ...@@ -94,7 +95,7 @@ struct UserMetadata {
AccountId account_id; AccountId account_id;
std::string display_name; std::string display_name;
bool enable_pin = false; bool enable_pin = false;
bool enable_click_to_unlock = false; bool enable_tap_to_unlock = false;
bool enable_auth = true; bool enable_auth = true;
user_manager::UserType type = user_manager::USER_TYPE_REGULAR; user_manager::UserType type = user_manager::USER_TYPE_REGULAR;
mojom::EasyUnlockIconId easy_unlock_id = mojom::EasyUnlockIconId::NONE; mojom::EasyUnlockIconId easy_unlock_id = mojom::EasyUnlockIconId::NONE;
...@@ -250,6 +251,15 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -250,6 +251,15 @@ class LockDebugView::DebugDataDispatcherTransformer
debug_user->enable_pin); debug_user->enable_pin);
} }
// Activates or deactivates tap unlock for the user at |user_index|.
void ToggleTapStateForUserIndex(size_t user_index) {
DCHECK(user_index >= 0 && user_index < debug_users_.size());
UserMetadata* debug_user = &debug_users_[user_index];
debug_user->enable_tap_to_unlock = !debug_user->enable_tap_to_unlock;
debug_dispatcher_.SetTapToUnlockEnabledForUser(
debug_user->account_id, debug_user->enable_tap_to_unlock);
}
// Enables click to auth for the user at |user_index|. // Enables click to auth for the user at |user_index|.
void CycleEasyUnlockForUserIndex(size_t user_index) { void CycleEasyUnlockForUserIndex(size_t user_index) {
DCHECK(user_index >= 0 && user_index < debug_users_.size()); DCHECK(user_index >= 0 && user_index < debug_users_.size());
...@@ -278,7 +288,7 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -278,7 +288,7 @@ class LockDebugView::DebugDataDispatcherTransformer
debug_user->easy_unlock_id = get_next_id(debug_user->easy_unlock_id); debug_user->easy_unlock_id = get_next_id(debug_user->easy_unlock_id);
// Enable/disable click to unlock. // Enable/disable click to unlock.
debug_user->enable_click_to_unlock = debug_user->enable_tap_to_unlock =
debug_user->easy_unlock_id == mojom::EasyUnlockIconId::UNLOCKED; debug_user->easy_unlock_id == mojom::EasyUnlockIconId::UNLOCKED;
// Prepare icon that we will show. // Prepare icon that we will show.
...@@ -300,8 +310,8 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -300,8 +310,8 @@ class LockDebugView::DebugDataDispatcherTransformer
// Show icon and enable/disable click to unlock. // Show icon and enable/disable click to unlock.
debug_dispatcher_.ShowEasyUnlockIcon(debug_user->account_id, icon); debug_dispatcher_.ShowEasyUnlockIcon(debug_user->account_id, icon);
debug_dispatcher_.SetClickToUnlockEnabledForUser( debug_dispatcher_.SetTapToUnlockEnabledForUser(
debug_user->account_id, debug_user->enable_click_to_unlock); debug_user->account_id, debug_user->enable_tap_to_unlock);
} }
// Enables fingerprint auth for the user at |user_index|. // Enables fingerprint auth for the user at |user_index|.
...@@ -423,13 +433,13 @@ class LockDebugView::DebugDataDispatcherTransformer ...@@ -423,13 +433,13 @@ class LockDebugView::DebugDataDispatcherTransformer
} }
} }
} }
void OnClickToUnlockEnabledForUserChanged(const AccountId& user, void OnTapToUnlockEnabledForUserChanged(const AccountId& user,
bool enabled) override { bool enabled) override {
// Forward notification only if the user is currently being shown. // Forward notification only if the user is currently being shown.
for (size_t i = 0u; i < debug_users_.size(); ++i) { for (size_t i = 0u; i < debug_users_.size(); ++i) {
if (debug_users_[i].account_id == user) { if (debug_users_[i].account_id == user) {
debug_users_[i].enable_click_to_unlock = enabled; debug_users_[i].enable_tap_to_unlock = enabled;
debug_dispatcher_.SetClickToUnlockEnabledForUser(user, enabled); debug_dispatcher_.SetTapToUnlockEnabledForUser(user, enabled);
break; break;
} }
} }
...@@ -899,6 +909,10 @@ void LockDebugView::ButtonPressed(views::Button* sender, ...@@ -899,6 +909,10 @@ void LockDebugView::ButtonPressed(views::Button* sender,
if (sender->id() == ButtonId::kPerUserTogglePin) if (sender->id() == ButtonId::kPerUserTogglePin)
debug_data_dispatcher_->TogglePinStateForUserIndex(sender->tag()); debug_data_dispatcher_->TogglePinStateForUserIndex(sender->tag());
// Enable or disable tap.
if (sender->id() == ButtonId::kPerUserToggleTap)
debug_data_dispatcher_->ToggleTapStateForUserIndex(sender->tag());
// Cycle easy unlock. // Cycle easy unlock.
if (sender->id() == ButtonId::kPerUserCycleEasyUnlockState) if (sender->id() == ButtonId::kPerUserCycleEasyUnlockState)
debug_data_dispatcher_->CycleEasyUnlockForUserIndex(sender->tag()); debug_data_dispatcher_->CycleEasyUnlockForUserIndex(sender->tag());
...@@ -948,6 +962,7 @@ void LockDebugView::UpdatePerUserActionContainer() { ...@@ -948,6 +962,7 @@ void LockDebugView::UpdatePerUserActionContainer() {
row->AddChildView(name); row->AddChildView(name);
AddButton("Toggle PIN", ButtonId::kPerUserTogglePin, row)->set_tag(i); AddButton("Toggle PIN", ButtonId::kPerUserTogglePin, row)->set_tag(i);
AddButton("Toggle Tap", ButtonId::kPerUserToggleTap, row)->set_tag(i);
AddButton("Cycle easy unlock", ButtonId::kPerUserCycleEasyUnlockState, row) AddButton("Cycle easy unlock", ButtonId::kPerUserCycleEasyUnlockState, row)
->set_tag(i); ->set_tag(i);
AddButton("Cycle fingerprint unlock", AddButton("Cycle fingerprint unlock",
......
...@@ -491,6 +491,7 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods) { ...@@ -491,6 +491,7 @@ void LoginAuthUserView::SetAuthMethods(uint32_t auth_methods) {
disabled_auth_message_->SetVisible(auth_disabled); disabled_auth_message_->SetVisible(auth_disabled);
password_view_->SetEnabled(has_password); password_view_->SetEnabled(has_password);
password_view_->SetEnabledOnEmptyPassword(has_tap);
password_view_->SetFocusEnabledForChildViews(has_password); password_view_->SetFocusEnabledForChildViews(has_password);
password_view_->SetVisible(!hide_auth); password_view_->SetVisible(!hide_auth);
password_view_->layer()->SetOpacity(has_password ? 1 : 0); password_view_->layer()->SetOpacity(has_password ? 1 : 0);
......
...@@ -20,7 +20,7 @@ void LoginDataDispatcher::Observer::OnAuthEnabledForUserChanged( ...@@ -20,7 +20,7 @@ void LoginDataDispatcher::Observer::OnAuthEnabledForUserChanged(
bool enabled, bool enabled,
const base::Optional<base::Time>& auth_reenabled_time) {} const base::Optional<base::Time>& auth_reenabled_time) {}
void LoginDataDispatcher::Observer::OnClickToUnlockEnabledForUserChanged( void LoginDataDispatcher::Observer::OnTapToUnlockEnabledForUserChanged(
const AccountId& user, const AccountId& user,
bool enabled) {} bool enabled) {}
...@@ -95,10 +95,10 @@ void LoginDataDispatcher::SetAuthEnabledForUser( ...@@ -95,10 +95,10 @@ void LoginDataDispatcher::SetAuthEnabledForUser(
} }
} }
void LoginDataDispatcher::SetClickToUnlockEnabledForUser(const AccountId& user, void LoginDataDispatcher::SetTapToUnlockEnabledForUser(const AccountId& user,
bool enabled) { bool enabled) {
for (auto& observer : observers_) for (auto& observer : observers_)
observer.OnClickToUnlockEnabledForUserChanged(user, enabled); observer.OnTapToUnlockEnabledForUserChanged(user, enabled);
} }
void LoginDataDispatcher::SetForceOnlineSignInForUser(const AccountId& user) { void LoginDataDispatcher::SetForceOnlineSignInForUser(const AccountId& user) {
......
...@@ -57,8 +57,8 @@ class ASH_EXPORT LoginDataDispatcher { ...@@ -57,8 +57,8 @@ class ASH_EXPORT LoginDataDispatcher {
const base::Optional<base::Time>& auth_reenabled_time); const base::Optional<base::Time>& auth_reenabled_time);
// Called when the given user can click their pod to unlock. // Called when the given user can click their pod to unlock.
virtual void OnClickToUnlockEnabledForUserChanged(const AccountId& user, virtual void OnTapToUnlockEnabledForUserChanged(const AccountId& user,
bool enabled); bool enabled);
// Called when |user| must authenticate online (e.g. when OAuth refresh // Called when |user| must authenticate online (e.g. when OAuth refresh
// token is revoked). // token is revoked).
...@@ -121,7 +121,7 @@ class ASH_EXPORT LoginDataDispatcher { ...@@ -121,7 +121,7 @@ class ASH_EXPORT LoginDataDispatcher {
void SetAuthEnabledForUser(const AccountId& account_id, void SetAuthEnabledForUser(const AccountId& account_id,
bool is_enabled, bool is_enabled,
base::Optional<base::Time> auth_reenabled_time); base::Optional<base::Time> auth_reenabled_time);
void SetClickToUnlockEnabledForUser(const AccountId& user, bool enabled); void SetTapToUnlockEnabledForUser(const AccountId& user, bool enabled);
void SetForceOnlineSignInForUser(const AccountId& user); void SetForceOnlineSignInForUser(const AccountId& user);
void SetLockScreenNoteState(mojom::TrayActionState state); void SetLockScreenNoteState(mojom::TrayActionState state);
void ShowEasyUnlockIcon(const AccountId& user, void ShowEasyUnlockIcon(const AccountId& user,
......
...@@ -435,6 +435,11 @@ void LoginPasswordView::Init( ...@@ -435,6 +435,11 @@ void LoginPasswordView::Init(
on_easy_unlock_icon_tapped); on_easy_unlock_icon_tapped);
} }
void LoginPasswordView::SetEnabledOnEmptyPassword(bool enabled) {
enabled_on_empty_password_ = enabled;
UpdateUiState();
}
void LoginPasswordView::SetEasyUnlockIcon( void LoginPasswordView::SetEasyUnlockIcon(
mojom::EasyUnlockIconId id, mojom::EasyUnlockIconId id,
const base::string16& accessibility_label) { const base::string16& accessibility_label) {
...@@ -509,7 +514,8 @@ void LoginPasswordView::RequestFocus() { ...@@ -509,7 +514,8 @@ void LoginPasswordView::RequestFocus() {
} }
bool LoginPasswordView::OnKeyPressed(const ui::KeyEvent& event) { bool LoginPasswordView::OnKeyPressed(const ui::KeyEvent& event) {
if (event.key_code() == ui::KeyboardCode::VKEY_RETURN) { if (event.key_code() == ui::KeyboardCode::VKEY_RETURN &&
submit_button_->enabled()) {
SubmitPassword(); SubmitPassword();
return true; return true;
} }
...@@ -558,7 +564,8 @@ bool LoginPasswordView::HandleKeyEvent(views::Textfield* sender, ...@@ -558,7 +564,8 @@ bool LoginPasswordView::HandleKeyEvent(views::Textfield* sender,
} }
void LoginPasswordView::UpdateUiState() { void LoginPasswordView::UpdateUiState() {
bool is_enabled = !textfield_->text().empty() && !textfield_->read_only(); bool is_enabled = !textfield_->read_only() &&
(enabled_on_empty_password_ || !textfield_->text().empty());
submit_button_->SetEnabled(is_enabled); submit_button_->SetEnabled(is_enabled);
SkColor color = is_enabled SkColor color = is_enabled
? login_constants::kButtonEnabledColor ? login_constants::kButtonEnabledColor
...@@ -575,6 +582,7 @@ void LoginPasswordView::OnCapsLockChanged(bool enabled) { ...@@ -575,6 +582,7 @@ void LoginPasswordView::OnCapsLockChanged(bool enabled) {
} }
void LoginPasswordView::SubmitPassword() { void LoginPasswordView::SubmitPassword() {
DCHECK(submit_button_->enabled());
if (textfield_->read_only()) if (textfield_->read_only())
return; return;
on_submit_.Run(textfield_->text()); on_submit_.Run(textfield_->text());
......
...@@ -75,6 +75,9 @@ class ASH_EXPORT LoginPasswordView : public views::View, ...@@ -75,6 +75,9 @@ class ASH_EXPORT LoginPasswordView : public views::View,
const OnEasyUnlockIconHovered& on_easy_unlock_icon_hovered, const OnEasyUnlockIconHovered& on_easy_unlock_icon_hovered,
const OnEasyUnlockIconTapped& on_easy_unlock_icon_tapped); const OnEasyUnlockIconTapped& on_easy_unlock_icon_tapped);
// Is the password field enabled when there is no text?
void SetEnabledOnEmptyPassword(bool enabled);
// Change the active icon for easy unlock. // Change the active icon for easy unlock.
void SetEasyUnlockIcon(mojom::EasyUnlockIconId id, void SetEasyUnlockIcon(mojom::EasyUnlockIconId id,
const base::string16& accessibility_label); const base::string16& accessibility_label);
...@@ -137,6 +140,9 @@ class ASH_EXPORT LoginPasswordView : public views::View, ...@@ -137,6 +140,9 @@ class ASH_EXPORT LoginPasswordView : public views::View,
OnPasswordSubmit on_submit_; OnPasswordSubmit on_submit_;
OnPasswordTextChanged on_password_text_changed_; OnPasswordTextChanged on_password_text_changed_;
// Is the password field enabled when there is no text?
bool enabled_on_empty_password_ = false;
views::View* password_row_ = nullptr; views::View* password_row_ = nullptr;
views::Textfield* textfield_ = nullptr; views::Textfield* textfield_ = nullptr;
......
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