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. ...@@ -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"> <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 Too many fingerprint attempts
</message> </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"> <message name="IDS_ASH_IN_SESSION_AUTH_HELP" desc="Label of a button in the auth dialog to open a help article">
Need help? Need help?
</message> </message>
......
30bd119e0aeefb9ee0f8997ec94a5e1088362a95
\ No newline at end of file
...@@ -540,6 +540,18 @@ void AuthDialogContentsView::AddActionButtonsView() { ...@@ -540,6 +540,18 @@ void AuthDialogContentsView::AddActionButtonsView() {
buttons_layout->set_main_axis_alignment( buttons_layout->set_main_axis_alignment(
views::BoxLayout::MainAxisAlignment::kStart); 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_ = help_button_ =
action_view_container_->AddChildView(std::make_unique<views::LabelButton>( action_view_container_->AddChildView(std::make_unique<views::LabelButton>(
base::BindRepeating(&AuthDialogContentsView::OnNeedHelpButtonPressed, base::BindRepeating(&AuthDialogContentsView::OnNeedHelpButtonPressed,
...@@ -551,6 +563,10 @@ void AuthDialogContentsView::AddActionButtonsView() { ...@@ -551,6 +563,10 @@ void AuthDialogContentsView::AddActionButtonsView() {
gfx::Size(kContainerPreferredWidth, help_button_->height())); gfx::Size(kContainerPreferredWidth, help_button_->height()));
} }
void AuthDialogContentsView::OnCancelButtonPressed(const ui::Event& event) {
InSessionAuthDialogController::Get()->Cancel();
}
void AuthDialogContentsView::OnNeedHelpButtonPressed(const ui::Event& event) { void AuthDialogContentsView::OnNeedHelpButtonPressed(const ui::Event& event) {
InSessionAuthDialogController::Get()->OpenInSessionAuthHelpPage(); InSessionAuthDialogController::Get()->OpenInSessionAuthHelpPage();
} }
......
...@@ -113,6 +113,9 @@ class AuthDialogContentsView : public views::View { ...@@ -113,6 +113,9 @@ class AuthDialogContentsView : public views::View {
void OnFingerprintAuthComplete(bool success, void OnFingerprintAuthComplete(bool success,
FingerprintState fingerprint_state); FingerprintState fingerprint_state);
// Called when the cancel button is pressed.
void OnCancelButtonPressed(const ui::Event& event);
// Called when the "Need help?" button is pressed. // Called when the "Need help?" button is pressed.
void OnNeedHelpButtonPressed(const ui::Event& event); void OnNeedHelpButtonPressed(const ui::Event& event);
...@@ -148,6 +151,9 @@ class AuthDialogContentsView : public views::View { ...@@ -148,6 +151,9 @@ class AuthDialogContentsView : public views::View {
FingerprintView* fingerprint_view_ = nullptr; 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. // A button to show a help center article.
views::LabelButton* help_button_ = nullptr; views::LabelButton* help_button_ = nullptr;
......
...@@ -15,7 +15,6 @@ ...@@ -15,7 +15,6 @@
#include "components/user_manager/known_user.h" #include "components/user_manager/known_user.h"
#include "ui/aura/window.h" #include "ui/aura/window.h"
#include "ui/views/widget/widget.h" #include "ui/views/widget/widget.h"
#include "ui/wm/core/focus_controller.h"
namespace ash { namespace ash {
...@@ -117,7 +116,6 @@ void InSessionAuthDialogControllerImpl::OnPinCanAuthenticate( ...@@ -117,7 +116,6 @@ void InSessionAuthDialogControllerImpl::OnPinCanAuthenticate(
auth_metadata.autosubmit_pin_length = auth_metadata.autosubmit_pin_length =
user_manager::known_user::GetUserPinLength(account_id); user_manager::known_user::GetUserPinLength(account_id);
source_window_tracker_.Remove(source_window); source_window_tracker_.Remove(source_window);
Shell::Get()->focus_controller()->AddObserver(this);
dialog_ = std::make_unique<InSessionAuthDialog>( dialog_ = std::make_unique<InSessionAuthDialog>(
auth_methods, source_window, origin_name, auth_metadata, avatar); auth_methods, source_window, origin_name, auth_metadata, avatar);
} }
...@@ -132,7 +130,6 @@ void InSessionAuthDialogControllerImpl::DestroyAuthenticationDialog() { ...@@ -132,7 +130,6 @@ void InSessionAuthDialogControllerImpl::DestroyAuthenticationDialog() {
dialog_.reset(); dialog_.reset();
source_window_tracker_.RemoveAll(); source_window_tracker_.RemoveAll();
Shell::Get()->focus_controller()->RemoveObserver(this);
} }
void InSessionAuthDialogControllerImpl::AuthenticateUserWithPin( void InSessionAuthDialogControllerImpl::AuthenticateUserWithPin(
...@@ -194,28 +191,9 @@ void InSessionAuthDialogControllerImpl::Cancel() { ...@@ -194,28 +191,9 @@ void InSessionAuthDialogControllerImpl::Cancel() {
std::move(finish_callback_).Run(false); 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() { void InSessionAuthDialogControllerImpl::OpenInSessionAuthHelpPage() {
DCHECK(client_); DCHECK(client_);
base::AutoReset<bool> scoped_ignore_focus(&should_ignore_focus_change_, true); client_->OpenInSessionAuthHelpPage();
help_window_tracker_.Add(client_->OpenInSessionAuthHelpPage());
} }
} // namespace ash } // namespace ash
...@@ -12,7 +12,6 @@ ...@@ -12,7 +12,6 @@
#include "base/callback.h" #include "base/callback.h"
#include "base/memory/weak_ptr.h" #include "base/memory/weak_ptr.h"
#include "base/optional.h" #include "base/optional.h"
#include "ui/aura/client/focus_change_observer.h"
#include "ui/aura/window_tracker.h" #include "ui/aura/window_tracker.h"
class AccountId; class AccountId;
...@@ -27,9 +26,7 @@ class InSessionAuthDialogClient; ...@@ -27,9 +26,7 @@ class InSessionAuthDialogClient;
class WebAuthnRequestRegistrarImpl; class WebAuthnRequestRegistrarImpl;
// InSessionAuthDialogControllerImpl persists as long as UI is running. // InSessionAuthDialogControllerImpl persists as long as UI is running.
class InSessionAuthDialogControllerImpl class InSessionAuthDialogControllerImpl : public InSessionAuthDialogController {
: public InSessionAuthDialogController,
public aura::client::FocusChangeObserver {
public: public:
InSessionAuthDialogControllerImpl(); InSessionAuthDialogControllerImpl();
InSessionAuthDialogControllerImpl(const InSessionAuthDialogControllerImpl&) = InSessionAuthDialogControllerImpl(const InSessionAuthDialogControllerImpl&) =
...@@ -51,10 +48,6 @@ class InSessionAuthDialogControllerImpl ...@@ -51,10 +48,6 @@ class InSessionAuthDialogControllerImpl
void OpenInSessionAuthHelpPage() override; void OpenInSessionAuthHelpPage() override;
void Cancel() override; void Cancel() override;
// aura::client::FocusChangeObserver overrides
void OnWindowFocused(aura::Window* gained_focus,
aura::Window* lost_focus) override;
private: private:
bool IsFingerprintAvailable(const AccountId& account_id); bool IsFingerprintAvailable(const AccountId& account_id);
void OnStartFingerprintAuthSession(AccountId account_id, void OnStartFingerprintAuthSession(AccountId account_id,
...@@ -88,13 +81,8 @@ class InSessionAuthDialogControllerImpl ...@@ -88,13 +81,8 @@ class InSessionAuthDialogControllerImpl
aura::WindowTracker source_window_tracker_; 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_; std::unique_ptr<WebAuthnRequestRegistrarImpl> webauthn_request_registrar_;
bool should_ignore_focus_change_ = false;
base::WeakPtrFactory<InSessionAuthDialogControllerImpl> weak_factory_{this}; 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