Commit 6f5eee5a authored by Jan Wilken Dörrie's avatar Jan Wilken Dörrie Committed by Commit Bot

[Passwords] Trigger Touch To Fill explicitly on Tap

This change modifies the Touch To Fill trigger logic to respond to
WebAutoFillClient's DidReceiveLeftMouseDownOrGestureTapInNode event.
Furthermore, this change introduces a ShouldSuppressKeyboard method on
PasswordAutofillAgent returning true iff Touch To Fill is currently
shown.

Bug: 1013131
Change-Id: Ic88d83594458b3a975cf1f7bea70e51f4a5e4bef
Reviewed-on: https://chromium-review.googlesource.com/c/chromium/src/+/1856040Reviewed-by: default avatarVadym Doroshenko <dvadym@chromium.org>
Reviewed-by: default avatarVasilii Sukhanov <vasilii@chromium.org>
Commit-Queue: Jan Wilken Dörrie <jdoerrie@chromium.org>
Cr-Commit-Position: refs/heads/master@{#705132}
parent 42c686dd
......@@ -47,8 +47,9 @@ void TouchToFillController::OnCredentialSelected(
password_manager::metrics_util::LogFilledCredentialIsFromAndroidApp(
password_manager::IsValidAndroidFacetURI(credential.origin_url.spec()));
driver_->FillSuggestion(credential.username, credential.password);
std::exchange(driver_, nullptr)->TouchToFillDismissed();
driver_->TouchToFillDismissed();
std::exchange(driver_, nullptr)
->FillSuggestion(credential.username, credential.password);
}
void TouchToFillController::OnDismiss() {
......
......@@ -1709,6 +1709,7 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillUsername) {
EXPECT_FALSE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_FALSE(password_autofill_agent_->TryToShowTouchToFill(random_element));
EXPECT_FALSE(password_autofill_agent_->ShouldSuppressKeyboard());
// This changes once fill data is simulated. |random_element| continue to
// have no fill data, though.
......@@ -1717,6 +1718,7 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillUsername) {
EXPECT_CALL(fake_driver_, ShowTouchToFill);
EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(username_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
base::RunLoop().RunUntilIdle();
}
......@@ -1726,6 +1728,7 @@ TEST_F(PasswordAutofillAgentTest, TryToShowTouchToFillPassword) {
EXPECT_CALL(fake_driver_, ShowTouchToFill);
EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
base::RunLoop().RunUntilIdle();
}
......@@ -1734,18 +1737,16 @@ TEST_F(PasswordAutofillAgentTest, TouchToFillDismissed) {
// Touch to fill will be shown multiple times until TouchToFillDismissed()
// gets called.
EXPECT_CALL(fake_driver_, ShowTouchToFill).Times(2);
EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(username_element_));
EXPECT_CALL(fake_driver_, ShowTouchToFill);
EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
base::RunLoop().RunUntilIdle();
password_autofill_agent_->TouchToFillDismissed();
EXPECT_FALSE(
password_autofill_agent_->TryToShowTouchToFill(username_element_));
EXPECT_FALSE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_FALSE(password_autofill_agent_->ShouldSuppressKeyboard());
base::RunLoop().RunUntilIdle();
// Reload the page and simulate fill.
......@@ -1758,6 +1759,7 @@ TEST_F(PasswordAutofillAgentTest, TouchToFillDismissed) {
EXPECT_CALL(fake_driver_, ShowTouchToFill);
EXPECT_TRUE(
password_autofill_agent_->TryToShowTouchToFill(password_element_));
EXPECT_TRUE(password_autofill_agent_->ShouldSuppressKeyboard());
base::RunLoop().RunUntilIdle();
}
......
......@@ -850,8 +850,10 @@ void AutofillAgent::DidReceiveLeftMouseDownOrGestureTapInNode(
DCHECK(!node.IsNull());
focused_node_was_last_clicked_ = node.Focused();
if (IsKeyboardAccessoryEnabled() || !focus_requires_scroll_)
if (IsTouchToFillEnabled() || IsKeyboardAccessoryEnabled() ||
!focus_requires_scroll_) {
HandleFocusChangeComplete();
}
}
void AutofillAgent::SelectControlDidChange(
......@@ -881,12 +883,9 @@ void AutofillAgent::SelectFieldOptionsChanged(
bool AutofillAgent::ShouldSuppressKeyboard(
const WebFormControlElement& element) {
// The keyboard should be suppressed if we can show the Touch To Fill UI.
//
// Note: This is currently only implemented for passwords. Consider supporting
// other autofill types in the future as well.
return IsTouchToFillEnabled() &&
password_autofill_agent_->TryToShowTouchToFill(element);
return password_autofill_agent_->ShouldSuppressKeyboard();
}
void AutofillAgent::SelectWasUpdated(
......@@ -913,6 +912,9 @@ void AutofillAgent::FormControlElementClicked(
if (!input_element && !form_util::IsTextAreaElement(element))
return;
if (IsTouchToFillEnabled())
password_autofill_agent_->TryToShowTouchToFill(element);
ShowSuggestionsOptions options;
options.autofill_on_empty_values = true;
// Show full suggestions when clicking on an already-focused form field.
......
......@@ -774,8 +774,16 @@ void PasswordAutofillAgent::MaybeCheckSafeBrowsingReputation(
#endif
}
bool PasswordAutofillAgent::ShouldSuppressKeyboard() {
// The keyboard should be suppressed if we are showing the Touch To Fill UI.
return touch_to_fill_state_ == TouchToFillState::kIsShowing;
}
bool PasswordAutofillAgent::TryToShowTouchToFill(
const WebFormControlElement& control_element) {
if (touch_to_fill_state_ != TouchToFillState::kShouldShow)
return false;
const WebInputElement* element = ToWebInputElement(&control_element);
WebInputElement username_element;
WebInputElement password_element;
......@@ -786,10 +794,8 @@ bool PasswordAutofillAgent::TryToShowTouchToFill(
return false;
}
if (!should_show_touch_to_fill_)
return false;
GetPasswordManagerDriver()->ShowTouchToFill();
touch_to_fill_state_ = TouchToFillState::kIsShowing;
return true;
}
......@@ -1197,7 +1203,7 @@ void PasswordAutofillAgent::SetLoggingState(bool active) {
}
void PasswordAutofillAgent::TouchToFillDismissed() {
should_show_touch_to_fill_ = false;
touch_to_fill_state_ = TouchToFillState::kWasShown;
}
void PasswordAutofillAgent::AnnotateFieldsWithParsingResult(
......@@ -1358,7 +1364,7 @@ void PasswordAutofillAgent::CleanupOnDocumentShutdown() {
autofilled_elements_cache_.clear();
last_updated_field_renderer_id_ = FormData::kNotSetFormRendererId;
last_updated_form_renderer_id_ = FormData::kNotSetFormRendererId;
should_show_touch_to_fill_ = true;
touch_to_fill_state_ = TouchToFillState::kShouldShow;
#if !defined(OS_ANDROID) && !defined(OS_IOS)
page_passwords_analyser_.Reset();
#endif
......
......@@ -179,6 +179,9 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
// no check request were sent from this frame load.
void MaybeCheckSafeBrowsingReputation(const blink::WebInputElement& element);
// Returns whether the soft keyboard should be suppressed.
bool ShouldSuppressKeyboard();
// Asks the agent to show the touch to fill UI for |control_element|. Returns
// whether the agent was able to do so.
bool TryToShowTouchToFill(
......@@ -247,6 +250,16 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
RESTRICTION_NON_EMPTY_PASSWORD
};
// Enumeration representing possible Touch To Fill states. This is used to
// make sure that Touch To Fill will only be shown in response to the first
// password form focus during a frame's life time and to suppress the soft
// keyboard when Touch To Fill is shown.
enum class TouchToFillState {
kShouldShow,
kIsShowing,
kWasShown,
};
struct PasswordInfo {
blink::WebInputElement password_field;
PasswordFormFillData fill_data;
......@@ -537,10 +550,9 @@ class PasswordAutofillAgent : public content::RenderFrameObserver,
// Contains renderer id of the form of the last updated input element.
uint32_t last_updated_form_renderer_id_ = FormData::kNotSetFormRendererId;
// Flag that determines whether we instruct the browser to show the Touch To
// Fill sheet if applicable. This is set to false when TouchToFillDismissed()
// is invoked and gets reset during CleanupOnDocumentShutdown.
bool should_show_touch_to_fill_ = true;
// Current state of Touch To Fill. This is reset during
// CleanupOnDocumentShutdown.
TouchToFillState touch_to_fill_state_ = TouchToFillState::kShouldShow;
DISALLOW_COPY_AND_ASSIGN(PasswordAutofillAgent);
};
......
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