Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(528)

Unified Diff: components/autofill/content/renderer/password_autofill_agent.cc

Issue 208453002: Add "previewing on hover" support for password field. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Created 6 years, 9 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View side-by-side diff with in-line comments
Download patch
Index: components/autofill/content/renderer/password_autofill_agent.cc
diff --git a/components/autofill/content/renderer/password_autofill_agent.cc b/components/autofill/content/renderer/password_autofill_agent.cc
index df8056242e3eed16495550ae170eeafec6200860..d664da78d6a7ddf9f79507587f216884ca4aadd9 100644
--- a/components/autofill/content/renderer/password_autofill_agent.cc
+++ b/components/autofill/content/renderer/password_autofill_agent.cc
@@ -218,6 +218,7 @@ PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view)
: content::RenderViewObserver(render_view),
usernames_usage_(NOTHING_TO_AUTOFILL),
web_view_(render_view->GetWebView()),
+ was_password_autofilled_(false),
weak_ptr_factory_(this) {
}
@@ -334,6 +335,10 @@ bool PasswordAutofillAgent::TextDidChangeInTextField(
return true;
}
+bool PasswordAutofillAgent::WasPasswordAutofilled() {
+ return was_password_autofilled_;
+}
+
bool PasswordAutofillAgent::TextFieldHandlingKeyDown(
const blink::WebInputElement& element,
const blink::WebKeyboardEvent& event) {
@@ -351,6 +356,23 @@ bool PasswordAutofillAgent::TextFieldHandlingKeyDown(
return true;
}
+bool PasswordAutofillAgent::DidSelectAutofillSuggestion(
+ const blink::WebNode& node,
+ const blink::WebString& username) {
+ blink::WebInputElement input;
+ PasswordInfo password;
+ if (!FindLoginInfo(node, &input, &password))
+ return false;
+
+ // Set the incoming |username| as the suggested value for the text field and
+ // |PreviewUserNameAndPassword| will do the rest.
+ input.setSuggestedValue(username);
+ return PreviewUserNameAndPassword(&input, &password.password_field,
+ password.fill_data,
+ true /* exact_username_match */,
+ true /* set_selection */);
+}
+
bool PasswordAutofillAgent::DidAcceptAutofillSuggestion(
const blink::WebNode& node,
const blink::WebString& username) {
@@ -750,37 +772,30 @@ void PasswordAutofillAgent::FillFormOnPasswordRecieved(
false /* set_selection */);
}
-bool PasswordAutofillAgent::FillUserNameAndPassword(
- blink::WebInputElement* username_element,
- blink::WebInputElement* password_element,
+std::vector<base::string16> PasswordAutofillAgent::FindUserNameAndPassword(
+ base::string16 current_username,
const PasswordFormFillData& fill_data,
- bool exact_username_match,
- bool set_selection) {
- base::string16 current_username = username_element->value();
- // username and password will contain the match found if any.
- base::string16 username;
- base::string16 password;
-
+ bool exact_username_match) {
+ std::vector<base::string16> username_and_password;
Ilya Sherman 2014/03/21 22:35:19 Please use out-parameters named "string16* usernam
ziran.sun 2014/03/25 18:25:26 Done.
// Look for any suitable matches to current field text.
if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, current_username,
exact_username_match)) {
- username = fill_data.basic_data.fields[0].value;
- password = fill_data.basic_data.fields[1].value;
- } else {
+ username_and_password.push_back(fill_data.basic_data.fields[0].value);
+ username_and_password.push_back(fill_data.basic_data.fields[1].value);
+ } else {
// Scan additional logins for a match.
PasswordFormFillData::LoginCollection::const_iterator iter;
for (iter = fill_data.additional_logins.begin();
iter != fill_data.additional_logins.end(); ++iter) {
if (DoUsernamesMatch(iter->first, current_username,
exact_username_match)) {
- username = iter->first;
- password = iter->second.password;
+ username_and_password.push_back(iter->first);
+ username_and_password.push_back(iter->second.password);
break;
}
}
-
// Check possible usernames.
- if (username.empty() && password.empty()) {
+ if (username_and_password.size() == 0) {
for (PasswordFormFillData::UsernamesCollection::const_iterator iter =
fill_data.other_possible_usernames.begin();
iter != fill_data.other_possible_usernames.end(); ++iter) {
@@ -788,19 +803,39 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
if (DoUsernamesMatch(iter->second[i], current_username,
exact_username_match)) {
usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED;
- username = iter->second[i];
- password = iter->first.password;
+ username_and_password.push_back(iter->second[i]);
+ username_and_password.push_back(iter->first.password);
break;
}
}
- if (!username.empty() && !password.empty())
+ if (username_and_password.size() == 2)
break;
}
}
}
- if (password.empty())
+ return username_and_password;
+}
+
+bool PasswordAutofillAgent::FillUserNameAndPassword(
+ blink::WebInputElement* username_element,
+ blink::WebInputElement* password_element,
+ const PasswordFormFillData& fill_data,
+ bool exact_username_match,
+ bool set_selection) {
+ base::string16 current_username = username_element->value();
+ // username and password will contain the match found if any.
+ std::vector<base::string16> username_and_password =
+ FindUserNameAndPassword (current_username,
+ fill_data,
+ exact_username_match);
+
+ if(username_and_password.size() < 2)
return false; // No match was found.
+ // username and password contain the match found.
+ base::string16 username = username_and_password[0];
+ base::string16 password = username_and_password[1];
+
// TODO(tkent): Check maxlength and pattern for both username and password
// fields.
@@ -824,6 +859,7 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
return false;
}
+ was_password_autofilled_ = password_element->isAutofilled();
// TODO(vabr): The "gatekeeper" feature is currently disabled on mobile.
// http://crbug.com/345510#c13
#if !defined(OS_ANDROID) || !defined(OS_IOS)
@@ -843,6 +879,51 @@ bool PasswordAutofillAgent::FillUserNameAndPassword(
return true;
}
+bool PasswordAutofillAgent::PreviewUserNameAndPassword(
+ blink::WebInputElement* username_element,
+ blink::WebInputElement* password_element,
+ const PasswordFormFillData& fill_data,
+ bool exact_username_match,
+ bool set_selection) {
+ base::string16 current_username = username_element->suggestedValue();
+ std::vector<base::string16> username_and_password =
+ FindUserNameAndPassword (current_username,
+ fill_data,
+ exact_username_match);
+
+ if (username_and_password.size() < 2)
+ return false; // No match was found.
+
+ // TODO(tkent): Check maxlength and pattern for both username and password
+ // fields.
+
+ // Don't preview username if password can't be set.
+ if (!IsElementAutocompletable(*password_element)) {
+ return false;
+ }
+
+ base::string16 username = username_and_password[0];
+ base::string16 password = username_and_password[1];
+
+ // Input matches the username, preview required values.
+ if (IsElementAutocompletable(*username_element)) {
+ username_element->setSuggestedValue(username);
+ username_element->setAutofilled(true);
+
+ if (set_selection) {
+ username_element->setSelectionRange(current_username.length(),
+ username.length());
Ilya Sherman 2014/03/21 22:35:19 This will always set an empty selection, right? T
ziran.sun 2014/03/25 18:25:26 I tried to replace current_username.length() with
+ }
+ } else if (current_username != username) {
+ return false;
+ }
+
+ was_password_autofilled_ = password_element->isAutofilled();
+ password_element->setSuggestedValue(password);
+ password_element->setAutofilled(true);
+ return true;
+}
+
void PasswordAutofillAgent::PerformInlineAutocomplete(
const blink::WebInputElement& username_input,
const blink::WebInputElement& password_input,

Powered by Google App Engine
This is Rietveld 408576698