OLD | NEW |
1 // Copyright 2013 The Chromium Authors. All rights reserved. | 1 // Copyright 2013 The Chromium Authors. All rights reserved. |
2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
4 | 4 |
5 #include "components/autofill/content/renderer/password_form_conversion_utils.h" | 5 #include "components/autofill/content/renderer/password_form_conversion_utils.h" |
6 | 6 |
7 #include <vector> | 7 #include <vector> |
8 | 8 |
9 #include "base/lazy_instance.h" | 9 #include "base/lazy_instance.h" |
10 #include "base/memory/scoped_ptr.h" | 10 #include "base/memory/scoped_ptr.h" |
(...skipping 174 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
185 const std::map<autofill::FormData, autofill::FormFieldData>& | 185 const std::map<autofill::FormData, autofill::FormFieldData>& |
186 form_predictions, | 186 form_predictions, |
187 WebVector<WebFormControlElement>* control_elements, | 187 WebVector<WebFormControlElement>* control_elements, |
188 WebInputElement* predicted_username_element) { | 188 WebInputElement* predicted_username_element) { |
189 FormData form_data; | 189 FormData form_data; |
190 if (!WebFormElementToFormData(form, WebFormControlElement(), EXTRACT_NONE, | 190 if (!WebFormElementToFormData(form, WebFormControlElement(), EXTRACT_NONE, |
191 &form_data, nullptr)) { | 191 &form_data, nullptr)) { |
192 return; | 192 return; |
193 } | 193 } |
194 | 194 |
195 // Prediction forms are not user submitted, but |form| can be user submitted. | 195 // Matching only requires that action and name of the form match to allow |
196 // We don't care about this flag for finding predictions, so set it to false. | 196 // the username to be updated even if the form is changed after page load. |
197 form_data.user_submitted = false; | 197 // See https://crbug.com/476092 for more details. |
198 auto predictions_iterator = form_predictions.find(form_data); | 198 auto predictions_iterator = form_predictions.begin(); |
| 199 for (;predictions_iterator != form_predictions.end(); |
| 200 ++predictions_iterator) { |
| 201 if (predictions_iterator->first.action == form_data.action && |
| 202 predictions_iterator->first.name == form_data.name) { |
| 203 break; |
| 204 } |
| 205 } |
| 206 |
199 if (predictions_iterator == form_predictions.end()) | 207 if (predictions_iterator == form_predictions.end()) |
200 return; | 208 return; |
201 | 209 |
202 std::vector<blink::WebFormControlElement> autofillable_elements = | 210 std::vector<blink::WebFormControlElement> autofillable_elements = |
203 ExtractAutofillableElementsFromSet(*control_elements); | 211 ExtractAutofillableElementsFromSet(*control_elements); |
204 DCHECK_EQ(autofillable_elements.size(), form_data.fields.size()); | |
205 | 212 |
206 const autofill::FormFieldData& username_field = predictions_iterator->second; | 213 const autofill::FormFieldData& username_field = predictions_iterator->second; |
207 autofill::FormFieldData form_field; | |
208 for (size_t i = 0; i < autofillable_elements.size(); ++i) { | 214 for (size_t i = 0; i < autofillable_elements.size(); ++i) { |
209 if (form_data.fields[i].SameFieldAs(username_field)) { | 215 if (autofillable_elements[i].nameForAutofill() == username_field.name) { |
210 WebInputElement* input_element = | 216 WebInputElement* input_element = |
211 toWebInputElement(&autofillable_elements[i]); | 217 toWebInputElement(&autofillable_elements[i]); |
212 if (input_element) { | 218 if (input_element) { |
213 *predicted_username_element = *input_element; | 219 *predicted_username_element = *input_element; |
214 } | 220 } |
215 break; | 221 break; |
216 } | 222 } |
217 } | 223 } |
218 } | 224 } |
219 | 225 |
(...skipping 230 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... |
450 WebFormElementToFormData(web_form, | 456 WebFormElementToFormData(web_form, |
451 blink::WebFormControlElement(), | 457 blink::WebFormControlElement(), |
452 EXTRACT_NONE, | 458 EXTRACT_NONE, |
453 &password_form->form_data, | 459 &password_form->form_data, |
454 NULL /* FormFieldData */); | 460 NULL /* FormFieldData */); |
455 | 461 |
456 return password_form.Pass(); | 462 return password_form.Pass(); |
457 } | 463 } |
458 | 464 |
459 } // namespace autofill | 465 } // namespace autofill |
OLD | NEW |