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

Unified Diff: chrome/renderer/password_autocomplete_manager.cc

Issue 6271007: PasswordManager fills up text input field with password, or PM crashes chrome tab/window/session (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src/chrome/renderer
Patch Set: Comment nits. Created 9 years, 11 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
« no previous file with comments | « no previous file | no next file » | no next file with comments »
Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
Index: chrome/renderer/password_autocomplete_manager.cc
diff --git a/chrome/renderer/password_autocomplete_manager.cc b/chrome/renderer/password_autocomplete_manager.cc
index f851f9adb86e96150e0f3131c185187ee8d5b211..83e633485c52235f2c9881fee892e5a500e8e858 100644
--- a/chrome/renderer/password_autocomplete_manager.cc
+++ b/chrome/renderer/password_autocomplete_manager.cc
@@ -53,21 +53,40 @@ static bool FindFormInputElements(WebKit::WebFormElement* fe,
for (size_t j = 0; j < data.fields.size(); j++) {
WebKit::WebVector<WebKit::WebNode> temp_elements;
fe->getNamedElements(data.fields[j].name(), temp_elements);
- if (temp_elements.isEmpty()) {
- // We didn't find a required element. This is not the right form.
- // Make sure no input elements from a partially matched form in this
- // iteration remain in the result set.
- // Note: clear will remove a reference from each InputElement.
+
+ // Match the first input element, if any.
+ // |getNamedElements| may return non-input elements where the names match,
+ // so the results are filtered for input elements.
+ // If more than one match is made, then we have ambiguity (due to misuse
+ // of "name" attribute) so is it considered not found.
+ bool found_input = false;
+ for (size_t i = 0; i < temp_elements.size(); ++i) {
+ if (temp_elements[i].to<WebKit::WebElement>().hasTagName("input")) {
+ // Check for a non-unique match.
+ if (found_input) {
+ found_input = false;
+ break;
+ }
+
+ // This element matched, add it to our temporary result. It's possible
+ // there are multiple matches, but for purposes of identifying the form
+ // one suffices and if some function needs to deal with multiple
+ // matching elements it can get at them through the FormElement*.
+ // Note: This assignment adds a reference to the InputElement.
+ result->input_elements[data.fields[j].name()] =
+ temp_elements[i].to<WebKit::WebInputElement>();
+ found_input = true;
+ }
+ }
+
+ // A required element was not found. This is not the right form.
+ // Make sure no input elements from a partially matched form in this
+ // iteration remain in the result set.
+ // Note: clear will remove a reference from each InputElement.
+ if (!found_input) {
result->input_elements.clear();
return false;
}
- // This element matched, add it to our temporary result. It's possible there
- // are multiple matches, but for purposes of identifying the form one
- // suffices and if some function needs to deal with multiple matching
- // elements it can get at them through the FormElement*.
- // Note: This assignment adds a reference to the InputElement.
- result->input_elements[data.fields[j].name()] =
- temp_elements[0].to<WebKit::WebInputElement>();
}
return true;
}
@@ -128,7 +147,7 @@ bool FillForm(FormElements* fe, const webkit_glue::FormData& data) {
for (FormInputElementMap::iterator it = fe->input_elements.begin();
it != fe->input_elements.end(); ++it) {
- WebKit::WebInputElement& element = it->second;
+ WebKit::WebInputElement element = it->second;
if (!element.value().isEmpty()) // Don't overwrite pre-filled values.
continue;
if (element.isPasswordField() &&
« no previous file with comments | « no previous file | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698