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 9e3e0d87fef189c727540f73b52222a8dd24e80b..19275aeb46f6bdf0d0a60ac265e4d7ce89a3e9bc 100644 |
--- a/components/autofill/content/renderer/password_autofill_agent.cc |
+++ b/components/autofill/content/renderer/password_autofill_agent.cc |
@@ -192,6 +192,14 @@ bool IsElementAutocompletable(const blink::WebInputElement& element) { |
element.autoComplete()); |
} |
+// Returns |true| if element1 and element2 are IsElementAutocompletable. |
+// Otherwise returns |false|. |
+bool IsElementsAutocompletable(const blink::WebInputElement& element1, |
Mike West
2014/09/18 10:25:14
Nit: _Are_ElementsAutocompletable.
|
+ const blink::WebInputElement& element2) { |
+ return IsElementAutocompletable(element1) && |
+ IsElementAutocompletable(element2); |
+} |
+ |
// Returns true if the password specified in |form| is a default value. |
bool PasswordValueIsDefault(const PasswordForm& form, |
blink::WebFormElement form_element) { |
@@ -355,8 +363,7 @@ bool PasswordAutofillAgent::TextDidChangeInTextField( |
if (iter->second.fill_data.wait_for_username) |
return false; |
- if (!element.isText() || !IsElementAutocompletable(element) || |
- !IsElementAutocompletable(password)) { |
+ if (!element.isText() || !IsElementsAutocompletable(element, password)) { |
return false; |
} |
@@ -406,8 +413,8 @@ bool PasswordAutofillAgent::FillSuggestion( |
PasswordInfo* password_info; |
if (!FindLoginInfo(node, &username_element, &password_info) || |
- !IsElementAutocompletable(username_element) || |
- !IsElementAutocompletable(password_info->password_field)) { |
+ !IsElementsAutocompletable(username_element, |
+ password_info->password_field)) { |
return false; |
} |
@@ -430,8 +437,8 @@ bool PasswordAutofillAgent::PreviewSuggestion( |
PasswordInfo* password_info; |
if (!FindLoginInfo(node, &username_element, &password_info) || |
- !IsElementAutocompletable(username_element) || |
- !IsElementAutocompletable(password_info->password_field)) { |
+ !IsElementsAutocompletable(username_element, |
+ password_info->password_field)) { |
return false; |
} |
@@ -473,8 +480,7 @@ bool PasswordAutofillAgent::ShowSuggestions( |
// should be shown. However, return |true| to indicate that this is a known |
// password form and that the request to show suggestions has been handled (as |
// a no-op). |
- if (!IsElementAutocompletable(element) || |
- !IsElementAutocompletable(iter->second.password_field)) |
+ if (!IsElementsAutocompletable(element, iter->second.password_field)) |
return true; |
return ShowSuggestionPopup(iter->second.fill_data, element, show_all); |
@@ -965,6 +971,10 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( |
base::string16 username; |
base::string16 password; |
+ // Don't fill username if password can't be set. |
+ if (!IsElementAutocompletable(*password_element)) |
vabr (Chromium)
2014/09/18 09:14:24
Since you asked explicitly: yes, moving this check
Deepak
2014/09/18 09:35:13
Thanks.
|
+ return false; |
+ |
// Look for any suitable matches to current field text. |
if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, |
current_username, |
@@ -973,49 +983,23 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( |
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; |
- break; |
- } |
- } |
- |
+ CheckLoginCollectionForMatch( |
+ fill_data, current_username, exact_username_match, username, password); |
// Check possible usernames. |
- 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) { |
- for (size_t i = 0; i < iter->second.size(); ++i) { |
- if (DoUsernamesMatch( |
- iter->second[i], current_username, exact_username_match)) { |
- usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; |
- username = iter->second[i]; |
- password = iter->first.password; |
- break; |
- } |
- } |
- if (!username.empty() && !password.empty()) |
- break; |
- } |
- } |
+ if (username.empty() && password.empty()) |
+ CheckUsernamesCollectionForMatch(fill_data, |
+ current_username, |
+ exact_username_match, |
+ username, |
+ password); |
} |
+ |
if (password.empty()) |
return false; // No match was found. |
// TODO(tkent): Check maxlength and pattern for both username and password |
// fields. |
- // Don't fill username if password can't be set. |
- if (!IsElementAutocompletable(*password_element)) { |
- return false; |
- } |
- |
// Input matches the username, fill in required values. |
if (IsElementAutocompletable(*username_element)) { |
username_element->setValue(username, true); |
@@ -1030,7 +1014,6 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( |
// as is, don't autofill a password. |
return false; |
} |
- |
// Wait to fill in the password until a user gesture occurs. This is to make |
// sure that we do not fill in the DOM with a password until we believe the |
// user is intentionally interacting with the page. |
@@ -1041,6 +1024,50 @@ bool PasswordAutofillAgent::FillUserNameAndPassword( |
return true; |
} |
+// Check additional names for match. |
+void PasswordAutofillAgent::CheckLoginCollectionForMatch( |
vabr (Chromium)
2014/09/18 09:14:24
Why separating the code into the two functions her
Deepak
2014/09/18 09:35:13
ok, I will make this again inline as earlier.
|
+ const PasswordFormFillData& fill_data, |
+ const base::string16 current_username, |
+ const bool exact_username_match, |
+ base::string16& username, |
+ base::string16& password) { |
+ for (PasswordFormFillData::LoginCollection::const_iterator 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; |
+ break; |
+ } |
+ } |
+} |
+ |
+// Check possible usernames. |
+void PasswordAutofillAgent::CheckUsernamesCollectionForMatch( |
+ const PasswordFormFillData& fill_data, |
+ const base::string16 current_username, |
+ const bool exact_username_match, |
+ base::string16& username, |
+ base::string16& password) { |
+ for (PasswordFormFillData::UsernamesCollection::const_iterator iter = |
+ fill_data.other_possible_usernames.begin(); |
+ iter != fill_data.other_possible_usernames.end(); |
+ ++iter) { |
+ for (size_t i = 0; i < iter->second.size(); ++i) { |
+ if (DoUsernamesMatch( |
+ iter->second[i], current_username, exact_username_match)) { |
+ usernames_usage_ = OTHER_POSSIBLE_USERNAME_SELECTED; |
+ username = iter->second[i]; |
+ password = iter->first.password; |
+ break; |
+ } |
+ } |
+ if (!username.empty() && !password.empty()) |
+ break; |
+ } |
+} |
+ |
void PasswordAutofillAgent::PerformInlineAutocomplete( |
const blink::WebInputElement& username_input, |
const blink::WebInputElement& password_input, |