| 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..d18084c19b5cf529d91b312b8f974e1ac91e7e82 100644
|
| --- a/components/autofill/content/renderer/password_autofill_agent.cc
|
| +++ b/components/autofill/content/renderer/password_autofill_agent.cc
|
| @@ -218,6 +218,8 @@ PasswordAutofillAgent::PasswordAutofillAgent(content::RenderView* render_view)
|
| : content::RenderViewObserver(render_view),
|
| usernames_usage_(NOTHING_TO_AUTOFILL),
|
| web_view_(render_view->GetWebView()),
|
| + was_password_autofilled_(false),
|
| + is_password_previewed_(false),
|
| weak_ptr_factory_(this) {
|
| }
|
|
|
| @@ -334,6 +336,14 @@ bool PasswordAutofillAgent::TextDidChangeInTextField(
|
| return true;
|
| }
|
|
|
| +bool PasswordAutofillAgent::WasPasswordAutofilled() {
|
| + return was_password_autofilled_;
|
| +}
|
| +
|
| +bool PasswordAutofillAgent::IsPasswordPreviewed() {
|
| + return is_password_previewed_;
|
| +}
|
| +
|
| bool PasswordAutofillAgent::TextFieldHandlingKeyDown(
|
| const blink::WebInputElement& element,
|
| const blink::WebKeyboardEvent& event) {
|
| @@ -351,7 +361,27 @@ bool PasswordAutofillAgent::TextFieldHandlingKeyDown(
|
| return true;
|
| }
|
|
|
| -bool PasswordAutofillAgent::DidAcceptAutofillSuggestion(
|
| +bool PasswordAutofillAgent::DidSelectSuggestion(
|
| + 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);
|
| + is_password_previewed_ = PreviewUserNameAndPassword(
|
| + &input,
|
| + &password.password_field,
|
| + password.fill_data,
|
| + true /* exact_username_match */,
|
| + true /* set_selection */);
|
| + return is_password_previewed_;
|
| +}
|
| +
|
| +bool PasswordAutofillAgent::DidAcceptSuggestion(
|
| const blink::WebNode& node,
|
| const blink::WebString& username) {
|
| blink::WebInputElement input;
|
| @@ -750,37 +780,31 @@ void PasswordAutofillAgent::FillFormOnPasswordRecieved(
|
| false /* set_selection */);
|
| }
|
|
|
| -bool PasswordAutofillAgent::FillUserNameAndPassword(
|
| - blink::WebInputElement* username_element,
|
| - blink::WebInputElement* password_element,
|
| +void PasswordAutofillAgent::FindUserNameAndPassword(
|
| + base::string16 current_username,
|
| + base::string16* username,
|
| + base::string16* password,
|
| 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) {
|
| // 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 = fill_data.basic_data.fields[0].value;
|
| + *password = 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 = iter->first;
|
| + *password = iter->second.password;
|
| break;
|
| }
|
| }
|
| -
|
| // Check possible usernames.
|
| - if (username.empty() && password.empty()) {
|
| + if (username->empty() && password->empty()) {
|
| for (PasswordFormFillData::UsernamesCollection::const_iterator iter =
|
| fill_data.other_possible_usernames.begin();
|
| iter != fill_data.other_possible_usernames.end(); ++iter) {
|
| @@ -788,16 +812,35 @@ 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 = iter->second[i];
|
| + *password = iter->first.password;
|
| break;
|
| }
|
| }
|
| - if (!username.empty() && !password.empty())
|
| + if (!username->empty() && !password->empty())
|
| break;
|
| }
|
| }
|
| }
|
| +}
|
| +
|
| +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.
|
| + base::string16 username;
|
| + base::string16 password;
|
| +
|
| + FindUserNameAndPassword (current_username,
|
| + &username,
|
| + &password,
|
| + fill_data,
|
| + exact_username_match);
|
| +
|
| if (password.empty())
|
| return false; // No match was found.
|
|
|
| @@ -824,6 +867,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 +887,53 @@ 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();
|
| + // username and password will contain the match found if any.
|
| + base::string16 username;
|
| + base::string16 password;
|
| +
|
| + FindUserNameAndPassword (current_username,
|
| + &username,
|
| + &password,
|
| + fill_data,
|
| + exact_username_match);
|
| +
|
| + if (password.empty())
|
| + 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;
|
| + }
|
| +
|
| + // 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());
|
| + }
|
| + } 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,
|
|
|