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

Side by Side Diff: components/autofill/content/renderer/password_form_conversion_utils.cc

Issue 1428283002: Fix of password autofilling on hidden passwords forms. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Comment fix Created 5 years, 1 month 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 unified diff | Download patch
« no previous file with comments | « components/autofill/content/renderer/password_autofill_agent.cc ('k') | no next file » | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
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 <string> 7 #include <string>
8 8
9 #include "base/i18n/case_conversion.h" 9 #include "base/i18n/case_conversion.h"
10 #include "base/lazy_instance.h" 10 #include "base/lazy_instance.h"
(...skipping 320 matching lines...) Expand 10 before | Expand all | Expand 10 after
331 } 331 }
332 332
333 std::map<WebInputElement, PasswordFormFieldPredictionType> predicted_elements; 333 std::map<WebInputElement, PasswordFormFieldPredictionType> predicted_elements;
334 if (form_predictions) { 334 if (form_predictions) {
335 FindPredictedElements(form, password_form->form_data, *form_predictions, 335 FindPredictedElements(form, password_form->form_data, *form_predictions,
336 &predicted_elements); 336 &predicted_elements);
337 } 337 }
338 338
339 std::string layout_sequence; 339 std::string layout_sequence;
340 layout_sequence.reserve(form.control_elements.size()); 340 layout_sequence.reserve(form.control_elements.size());
341 bool visible_passwords_fields_found = false;
341 for (size_t i = 0; i < form.control_elements.size(); ++i) { 342 for (size_t i = 0; i < form.control_elements.size(); ++i) {
342 WebFormControlElement control_element = form.control_elements[i]; 343 WebFormControlElement control_element = form.control_elements[i];
343 344
344 WebInputElement* input_element = toWebInputElement(&control_element); 345 WebInputElement* input_element = toWebInputElement(&control_element);
345 if (!input_element || !input_element->isEnabled()) 346 if (!input_element || !input_element->isEnabled())
346 continue; 347 continue;
347 348
348 if (input_element->isTextField()) { 349 if (input_element->isTextField()) {
349 if (input_element->isPasswordField()) 350 if (input_element->isPasswordField())
350 layout_sequence.push_back('P'); 351 layout_sequence.push_back('P');
351 else 352 else
352 layout_sequence.push_back('N'); 353 layout_sequence.push_back('N');
353 } 354 }
354 355
355 bool password_marked_by_autocomplete_attribute = 356 bool password_marked_by_autocomplete_attribute =
356 HasAutocompleteAttributeValue(*input_element, 357 HasAutocompleteAttributeValue(*input_element,
357 kAutocompleteCurrentPassword) || 358 kAutocompleteCurrentPassword) ||
358 HasAutocompleteAttributeValue(*input_element, kAutocompleteNewPassword); 359 HasAutocompleteAttributeValue(*input_element, kAutocompleteNewPassword);
359 360
360 // If the password field is readonly, the page is likely using a virtual 361 // If the password field is readonly, the page is likely using a virtual
361 // keyboard and bypassing the password field value (see 362 // keyboard and bypassing the password field value (see
362 // http://crbug.com/475488). There is nothing Chrome can do to fill 363 // http://crbug.com/475488). There is nothing Chrome can do to fill
363 // passwords for now. Continue processing in case when the password field 364 // passwords for now. Continue processing in case when the password field
364 // was made readonly by JavaScript before submission. We can do this by 365 // was made readonly by JavaScript before submission. We can do this by
365 // checking whether password element was updated not from JavaScript. 366 // checking whether password element was updated not from JavaScript.
366 if (input_element->isPasswordField() && 367 if (input_element->isPasswordField() &&
367 form_util::IsWebNodeVisible(*input_element) &&
368 (!input_element->isReadOnly() || 368 (!input_element->isReadOnly() ||
369 (nonscript_modified_values && 369 (nonscript_modified_values &&
370 nonscript_modified_values->find(*input_element) != 370 nonscript_modified_values->find(*input_element) !=
371 nonscript_modified_values->end()) || 371 nonscript_modified_values->end()) ||
372 password_marked_by_autocomplete_attribute)) { 372 password_marked_by_autocomplete_attribute)) {
373 if (form_util::IsWebNodeVisible(*input_element)) {
374 if (!visible_passwords_fields_found) {
375 // Remove all invisible passwords fields, we don't care about them
376 // anymore.
377 passwords.clear();
378 visible_passwords_fields_found = true;
379 }
380 } else {
381 if (visible_passwords_fields_found)
382 continue;
383 }
384
373 // We add the field to the list of password fields if it was not flagged 385 // We add the field to the list of password fields if it was not flagged
374 // as a special NOT_PASSWORD prediction by Autofill. The NOT_PASSWORD 386 // as a special NOT_PASSWORD prediction by Autofill. The NOT_PASSWORD
375 // mechanism exists because some webpages use the type "password" for 387 // mechanism exists because some webpages use the type "password" for
376 // fields which Autofill knows shouldn't be treated as passwords by the 388 // fields which Autofill knows shouldn't be treated as passwords by the
377 // Password Manager. This is ultimately bypassed if the field has 389 // Password Manager. This is ultimately bypassed if the field has
378 // autocomplete attributes. 390 // autocomplete attributes.
379 auto possible_password_element_iterator = 391 auto possible_password_element_iterator =
380 predicted_elements.find(*input_element); 392 predicted_elements.find(*input_element);
381 if (password_marked_by_autocomplete_attribute || 393 if (password_marked_by_autocomplete_attribute ||
382 possible_password_element_iterator == predicted_elements.end() || 394 possible_password_element_iterator == predicted_elements.end() ||
(...skipping 249 matching lines...) Expand 10 before | Expand all | Expand 10 after
632 } 644 }
633 645
634 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element, 646 bool HasAutocompleteAttributeValue(const blink::WebInputElement& element,
635 const char* value_in_lowercase) { 647 const char* value_in_lowercase) {
636 return base::LowerCaseEqualsASCII( 648 return base::LowerCaseEqualsASCII(
637 base::StringPiece16(element.getAttribute("autocomplete")), 649 base::StringPiece16(element.getAttribute("autocomplete")),
638 value_in_lowercase); 650 value_in_lowercase);
639 } 651 }
640 652
641 } // namespace autofill 653 } // namespace autofill
OLDNEW
« no previous file with comments | « components/autofill/content/renderer/password_autofill_agent.cc ('k') | no next file » | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698