Commit 0a92b0f6 authored by Yicheng Li's avatar Yicheng Li Committed by Commit Bot

ash: Add back cancel button for in-session auth

This is because users needs to explicitly know that they can reject
the authentication - tapping outside dialog to cancel is not clear
enough.

Bug: b:156258540, b:144861739
Change-Id: If47cd9bb76a48e6149eba3606cc1434db53662c2
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/2525855Reviewed-by: default avatarXiyuan Xia <xiyuan@chromium.org>
Commit-Queue: Yicheng Li <yichengli@chromium.org>
Cr-Commit-Position: refs/heads/master@{#825477}
parent 4509f70c
......@@ -2501,6 +2501,9 @@ This file contains the strings for ash.
<message name="IDS_ASH_IN_SESSION_AUTH_FINGERPRINT_ACCESSIBLE_DISABLED_FROM_ATTEMPTS" desc="Accessibility text read by chromevox when the user has made too many unsuccessful fingerprint unlock attempts; fingerprint is now disabled until the user authenticates with a different authentication method">
Too many fingerprint attempts
</message>
<message name="IDS_ASH_IN_SESSION_AUTH_CANCEL" desc="Label of a button in the auth dialog to cancelauthentication and close the dialog">
Cancel
</message>
<message name="IDS_ASH_IN_SESSION_AUTH_HELP" desc="Label of a button in the auth dialog to open a help article">
Need help?
</message>
......
30bd119e0aeefb9ee0f8997ec94a5e1088362a95
\ No newline at end of file
......@@ -540,6 +540,18 @@ void AuthDialogContentsView::AddActionButtonsView() {
buttons_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kStart);
cancel_button_ =
action_view_container_->AddChildView(std::make_unique<views::LabelButton>(
base::BindRepeating(&AuthDialogContentsView::OnCancelButtonPressed,
base::Unretained(this)),
l10n_util::GetStringUTF16(IDS_ASH_IN_SESSION_AUTH_CANCEL),
views::style::CONTEXT_BUTTON));
cancel_button_->SetEnabledTextColors(kTextColorPrimary);
auto* spacing = action_view_container_->AddChildView(
std::make_unique<NonAccessibleView>());
buttons_layout->SetFlexForView(spacing, 1);
help_button_ =
action_view_container_->AddChildView(std::make_unique<views::LabelButton>(
base::BindRepeating(&AuthDialogContentsView::OnNeedHelpButtonPressed,
......@@ -551,6 +563,10 @@ void AuthDialogContentsView::AddActionButtonsView() {
gfx::Size(kContainerPreferredWidth, help_button_->height()));
}
void AuthDialogContentsView::OnCancelButtonPressed(const ui::Event& event) {
InSessionAuthDialogController::Get()->Cancel();
}
void AuthDialogContentsView::OnNeedHelpButtonPressed(const ui::Event& event) {
InSessionAuthDialogController::Get()->OpenInSessionAuthHelpPage();
}
......
......@@ -113,6 +113,9 @@ class AuthDialogContentsView : public views::View {
void OnFingerprintAuthComplete(bool success,
FingerprintState fingerprint_state);
// Called when the cancel button is pressed.
void OnCancelButtonPressed(const ui::Event& event);
// Called when the "Need help?" button is pressed.
void OnNeedHelpButtonPressed(const ui::Event& event);
......@@ -148,6 +151,9 @@ class AuthDialogContentsView : public views::View {
FingerprintView* fingerprint_view_ = nullptr;
// A button to cancel authentication and close the dialog.
views::LabelButton* cancel_button_ = nullptr;
// A button to show a help center article.
views::LabelButton* help_button_ = nullptr;
......
......@@ -15,7 +15,6 @@
#include "components/user_manager/known_user.h"
#include "ui/aura/window.h"
#include "ui/views/widget/widget.h"
#include "ui/wm/core/focus_controller.h"
namespace ash {
......@@ -117,7 +116,6 @@ void InSessionAuthDialogControllerImpl::OnPinCanAuthenticate(
auth_metadata.autosubmit_pin_length =
user_manager::known_user::GetUserPinLength(account_id);
source_window_tracker_.Remove(source_window);
Shell::Get()->focus_controller()->AddObserver(this);
dialog_ = std::make_unique<InSessionAuthDialog>(
auth_methods, source_window, origin_name, auth_metadata, avatar);
}
......@@ -132,7 +130,6 @@ void InSessionAuthDialogControllerImpl::DestroyAuthenticationDialog() {
dialog_.reset();
source_window_tracker_.RemoveAll();
Shell::Get()->focus_controller()->RemoveObserver(this);
}
void InSessionAuthDialogControllerImpl::AuthenticateUserWithPin(
......@@ -194,28 +191,9 @@ void InSessionAuthDialogControllerImpl::Cancel() {
std::move(finish_callback_).Run(false);
}
void InSessionAuthDialogControllerImpl::OnWindowFocused(
aura::Window* gained_focus,
aura::Window* lost_focus) {
if (should_ignore_focus_change_)
return;
if (!dialog_)
return;
// No-op if focus moved to the help page or back to the dialog.
if (help_window_tracker_.Contains(gained_focus) ||
gained_focus == dialog_->widget()->GetNativeWindow()) {
return;
}
Cancel();
}
void InSessionAuthDialogControllerImpl::OpenInSessionAuthHelpPage() {
DCHECK(client_);
base::AutoReset<bool> scoped_ignore_focus(&should_ignore_focus_change_, true);
help_window_tracker_.Add(client_->OpenInSessionAuthHelpPage());
client_->OpenInSessionAuthHelpPage();
}
} // namespace ash
......@@ -12,7 +12,6 @@
#include "base/callback.h"
#include "base/memory/weak_ptr.h"
#include "base/optional.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/window_tracker.h"
class AccountId;
......@@ -27,9 +26,7 @@ class InSessionAuthDialogClient;
class WebAuthnRequestRegistrarImpl;
// InSessionAuthDialogControllerImpl persists as long as UI is running.
class InSessionAuthDialogControllerImpl
: public InSessionAuthDialogController,
public aura::client::FocusChangeObserver {
class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
public:
InSessionAuthDialogControllerImpl();
InSessionAuthDialogControllerImpl(const InSessionAuthDialogControllerImpl&) =
......@@ -51,10 +48,6 @@ class InSessionAuthDialogControllerImpl
void OpenInSessionAuthHelpPage() override;
void Cancel() override;
// aura::client::FocusChangeObserver overrides
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
private:
bool IsFingerprintAvailable(const AccountId& account_id);
void OnStartFingerprintAuthSession(AccountId account_id,
......@@ -88,13 +81,8 @@ class InSessionAuthDialogControllerImpl
aura::WindowTracker source_window_tracker_;
// Tracks windows that show the help article about in-session auth.
aura::WindowTracker help_window_tracker_;
std::unique_ptr<WebAuthnRequestRegistrarImpl> webauthn_request_registrar_;
bool should_ignore_focus_change_ = false;
base::WeakPtrFactory<InSessionAuthDialogControllerImpl> weak_factory_{this};
};
......
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