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

Side by Side Diff: chrome/renderer/autofill/password_autofill_manager.cc

Issue 9625026: Save password without an associated username. (Closed) Base URL: http://src.chromium.org/svn/trunk/src/
Patch Set: Modify the errors from Lint Created 8 years, 9 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 unified diff | Download patch | Annotate | Revision Log
OLDNEW
1 // Copyright (c) 2011 The Chromium Authors. All rights reserved. 1 // Copyright (c) 2011 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 "chrome/renderer/autofill/password_autofill_manager.h" 5 #include "chrome/renderer/autofill/password_autofill_manager.h"
6 6
7 #include "base/bind.h" 7 #include "base/bind.h"
8 #include "base/memory/scoped_ptr.h" 8 #include "base/memory/scoped_ptr.h"
9 #include "base/message_loop.h" 9 #include "base/message_loop.h"
10 #include "chrome/common/autofill_messages.h" 10 #include "chrome/common/autofill_messages.h"
(...skipping 405 matching lines...) Expand 10 before | Expand all | Expand 10 after
416 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms); 416 FindFormElements(render_view()->GetWebView(), form_data.basic_data, &forms);
417 FormElementsList::iterator iter; 417 FormElementsList::iterator iter;
418 for (iter = forms.begin(); iter != forms.end(); ++iter) { 418 for (iter = forms.begin(); iter != forms.end(); ++iter) {
419 scoped_ptr<FormElements> form_elements(*iter); 419 scoped_ptr<FormElements> form_elements(*iter);
420 420
421 // If wait_for_username is true, we don't want to initially fill the form 421 // If wait_for_username is true, we don't want to initially fill the form
422 // until the user types in a valid username. 422 // until the user types in a valid username.
423 if (!form_data.wait_for_username) 423 if (!form_data.wait_for_username)
424 FillForm(form_elements.get(), form_data.basic_data); 424 FillForm(form_elements.get(), form_data.basic_data);
425 425
426 // Attach autocomplete listener to enable selecting alternate logins.
427 // First, get pointers to username element.
428 WebKit::WebInputElement username_element =
429 form_elements->input_elements[form_data.basic_data.fields[0].name];
430
431 // Get pointer to password element. (We currently only support single 426 // Get pointer to password element. (We currently only support single
432 // password forms). 427 // password forms).
433 WebKit::WebInputElement password_element = 428 WebKit::WebInputElement password_element =
434 form_elements->input_elements[form_data.basic_data.fields[1].name]; 429 form_elements->input_elements[form_data.GetPasswordField().name];
435 430
436 // We might have already filled this form if there are two <form> elements 431 // If there is a username, set the username and login_to_password_info_.
437 // with identical markup. 432 if (form_data.GetDataType() ==
438 if (login_to_password_info_.find(username_element) != 433 webkit::forms::PasswordFormFillData::kUsernameAndPassword) {
439 login_to_password_info_.end()) 434 // Attach autocomplete listener to enable selecting alternate logins.
440 continue; 435 // First, get pointers to username element.
441 436 WebKit::WebInputElement username_element =
442 PasswordInfo password_info; 437 form_elements->input_elements[form_data.GetUsernameField().name];
443 password_info.fill_data = form_data; 438 // We might have already filled this form if there are two <form> elements
444 password_info.password_field = password_element; 439 // with identical markup.
445 login_to_password_info_[username_element] = password_info; 440 if (login_to_password_info_.find(username_element) !=
441 login_to_password_info_.end())
442 continue;
443 PasswordInfo password_info;
444 password_info.fill_data = form_data;
445 password_info.password_field = password_element;
446 login_to_password_info_[username_element] = password_info;
447 }
446 } 448 }
447 } 449 }
448 450
449 //////////////////////////////////////////////////////////////////////////////// 451 ////////////////////////////////////////////////////////////////////////////////
450 // PasswordAutofillManager, private: 452 // PasswordAutofillManager, private:
451 453
452 void PasswordAutofillManager::GetSuggestions( 454 void PasswordAutofillManager::GetSuggestions(
453 const webkit::forms::PasswordFormFillData& fill_data, 455 const webkit::forms::PasswordFormFillData& fill_data,
454 const string16& input, 456 const string16& input,
455 std::vector<string16>* suggestions) { 457 std::vector<string16>* suggestions) {
456 if (StartsWith(fill_data.basic_data.fields[0].value, input, false)) 458 if (fill_data.GetDataType() ==
457 suggestions->push_back(fill_data.basic_data.fields[0].value); 459 webkit::forms::PasswordFormFillData::kUsernameAndPassword) {
458 460 if (StartsWith(fill_data.GetUsernameField().value, input, false))
461 suggestions->push_back(fill_data.GetUsernameField().value);
462 }
459 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; 463 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter;
460 for (iter = fill_data.additional_logins.begin(); 464 for (iter = fill_data.additional_logins.begin();
461 iter != fill_data.additional_logins.end(); ++iter) { 465 iter != fill_data.additional_logins.end(); ++iter) {
462 if (StartsWith(iter->first, input, false)) 466 if (StartsWith(iter->first, input, false))
463 suggestions->push_back(iter->first); 467 suggestions->push_back(iter->first);
464 } 468 }
465 } 469 }
466 470
467 bool PasswordAutofillManager::ShowSuggestionPopup( 471 bool PasswordAutofillManager::ShowSuggestionPopup(
468 const webkit::forms::PasswordFormFillData& fill_data, 472 const webkit::forms::PasswordFormFillData& fill_data,
(...skipping 25 matching lines...) Expand all
494 WebKit::WebInputElement* username_element, 498 WebKit::WebInputElement* username_element,
495 WebKit::WebInputElement* password_element, 499 WebKit::WebInputElement* password_element,
496 const webkit::forms::PasswordFormFillData& fill_data, 500 const webkit::forms::PasswordFormFillData& fill_data,
497 bool exact_username_match, 501 bool exact_username_match,
498 bool set_selection) { 502 bool set_selection) {
499 string16 current_username = username_element->value(); 503 string16 current_username = username_element->value();
500 // username and password will contain the match found if any. 504 // username and password will contain the match found if any.
501 string16 username; 505 string16 username;
502 string16 password; 506 string16 password;
503 507
508 // If there isn't any username form, just exit.
509 // Because this function is used for the case
510 // that the username form and the possword form exist.
511 if (fill_data.GetDataType() ==
512 webkit::forms::PasswordFormFillData::kOnlyPassword) {
513 return false;
514 }
515
504 // Look for any suitable matches to current field text. 516 // Look for any suitable matches to current field text.
505 if (DoUsernamesMatch(fill_data.basic_data.fields[0].value, current_username, 517 if (DoUsernamesMatch(fill_data.GetUsernameField().value, current_username,
506 exact_username_match)) { 518 exact_username_match)) {
507 username = fill_data.basic_data.fields[0].value; 519 username = fill_data.GetUsernameField().value;
508 password = fill_data.basic_data.fields[1].value; 520 password = fill_data.GetPasswordField().value;
509 } else { 521 } else {
510 // Scan additional logins for a match. 522 // Scan additional logins for a match.
511 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter; 523 webkit::forms::PasswordFormFillData::LoginCollection::const_iterator iter;
512 for (iter = fill_data.additional_logins.begin(); 524 for (iter = fill_data.additional_logins.begin();
513 iter != fill_data.additional_logins.end(); ++iter) { 525 iter != fill_data.additional_logins.end(); ++iter) {
514 if (DoUsernamesMatch(iter->first, current_username, 526 if (DoUsernamesMatch(iter->first, current_username,
515 exact_username_match)) { 527 exact_username_match)) {
516 username = iter->first; 528 username = iter->first;
517 password = iter->second; 529 password = iter->second;
518 break; 530 break;
(...skipping 67 matching lines...) Expand 10 before | Expand all | Expand 10 after
586 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input); 598 LoginToPasswordInfoMap::iterator iter = login_to_password_info_.find(input);
587 if (iter == login_to_password_info_.end()) 599 if (iter == login_to_password_info_.end())
588 return false; 600 return false;
589 601
590 *found_input = input; 602 *found_input = input;
591 *found_password = iter->second; 603 *found_password = iter->second;
592 return true; 604 return true;
593 } 605 }
594 606
595 } // namespace autofill 607 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698