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

Side by Side Diff: components/autofill/core/common/password_form_fill_data.cc

Issue 548953002: [Password Manager] Modified to support saving passwords on forms without username fields. (Closed) Base URL: https://chromium.googlesource.com/chromium/src.git@master
Patch Set: Incorporated review changes and code refactoring. Created 6 years, 2 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
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/core/common/password_form_fill_data.h" 5 #include "components/autofill/core/common/password_form_fill_data.h"
6 6
7 #include "base/logging.h" 7 #include "base/logging.h"
8 #include "base/strings/utf_string_conversions.h" 8 #include "base/strings/utf_string_conversions.h"
9 #include "components/autofill/core/common/form_field_data.h" 9 #include "components/autofill/core/common/form_field_data.h"
10 10
(...skipping 21 matching lines...) Expand all
32 void InitPasswordFormFillData( 32 void InitPasswordFormFillData(
33 const PasswordForm& form_on_page, 33 const PasswordForm& form_on_page,
34 const PasswordFormMap& matches, 34 const PasswordFormMap& matches,
35 const PasswordForm* const preferred_match, 35 const PasswordForm* const preferred_match,
36 bool wait_for_username_before_autofill, 36 bool wait_for_username_before_autofill,
37 bool enable_other_possible_usernames, 37 bool enable_other_possible_usernames,
38 PasswordFormFillData* result) { 38 PasswordFormFillData* result) {
39 // Note that many of the |FormFieldData| members are not initialized for 39 // Note that many of the |FormFieldData| members are not initialized for
40 // |username_field| and |password_field| because they are currently not used 40 // |username_field| and |password_field| because they are currently not used
41 // by the password autocomplete code. 41 // by the password autocomplete code.
42 FormFieldData username_field; 42 if (!form_on_page.username_element.empty()) {
43 username_field.name = form_on_page.username_element; 43 FormFieldData username_field;
44 username_field.value = preferred_match->username_value; 44 username_field.name = form_on_page.username_element;
45 username_field.value = preferred_match->username_value;
46 result->basic_data.fields.push_back(username_field);
47 }
48
45 FormFieldData password_field; 49 FormFieldData password_field;
46 password_field.name = form_on_page.password_element; 50 password_field.name = form_on_page.password_element;
47 password_field.value = preferred_match->password_value; 51 password_field.value = preferred_match->password_value;
48 password_field.form_control_type = "password"; 52 password_field.form_control_type = "password";
53 result->basic_data.fields.push_back(password_field);
49 54
50 // Fill basic form data. 55 // Fill basic form data.
51 result->basic_data.origin = form_on_page.origin; 56 result->basic_data.origin = form_on_page.origin;
52 result->basic_data.action = form_on_page.action; 57 result->basic_data.action = form_on_page.action;
53 result->basic_data.fields.push_back(username_field);
54 result->basic_data.fields.push_back(password_field);
55 result->wait_for_username = wait_for_username_before_autofill; 58 result->wait_for_username = wait_for_username_before_autofill;
56
57 result->preferred_realm = preferred_match->original_signon_realm; 59 result->preferred_realm = preferred_match->original_signon_realm;
58 60
59 // Copy additional username/value pairs. 61 // Copy additional username/value pairs.
60 PasswordFormMap::const_iterator iter; 62 PasswordFormMap::const_iterator iter;
61 for (iter = matches.begin(); iter != matches.end(); iter++) { 63 for (iter = matches.begin(); iter != matches.end(); iter++) {
62 if (iter->second != preferred_match) { 64 if (iter->second != preferred_match) {
63 PasswordAndRealm value; 65 PasswordAndRealm value;
64 value.password = iter->second->password_value; 66 value.password = iter->second->password_value;
65 value.realm = iter->second->original_signon_realm; 67 value.realm = iter->second->original_signon_realm;
66 result->additional_logins[iter->first] = value; 68 result->additional_logins[iter->first] = value;
67 } 69 }
68 if (enable_other_possible_usernames && 70 if (enable_other_possible_usernames &&
69 !iter->second->other_possible_usernames.empty()) { 71 !iter->second->other_possible_usernames.empty()) {
70 // Note that there may be overlap between other_possible_usernames and 72 // Note that there may be overlap between other_possible_usernames and
71 // other saved usernames or with other other_possible_usernames. For now 73 // other saved usernames or with other other_possible_usernames. For now
72 // we will ignore this overlap as it should be a rare occurence. We may 74 // we will ignore this overlap as it should be a rare occurence. We may
73 // want to revisit this in the future. 75 // want to revisit this in the future.
74 UsernamesCollectionKey key; 76 UsernamesCollectionKey key;
75 key.username = iter->first; 77 key.username = iter->first;
76 key.password = iter->second->password_value; 78 key.password = iter->second->password_value;
77 key.realm = iter->second->original_signon_realm; 79 key.realm = iter->second->original_signon_realm;
78 result->other_possible_usernames[key] = 80 result->other_possible_usernames[key] =
79 iter->second->other_possible_usernames; 81 iter->second->other_possible_usernames;
80 } 82 }
81 } 83 }
82 } 84 }
83 85
84 } // namespace autofill 86 } // namespace autofill
OLDNEW

Powered by Google App Engine
This is Rietveld 408576698