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
3 // found in the LICENSE file.
5 #include "components/autofill/core/common/password_form_fill_data.h"
7 #include "base/strings/utf_string_conversions.h"
8 #include "components/autofill/core/common/form_field_data.h"
12 UsernamesCollectionKey::UsernamesCollectionKey() {}
14 UsernamesCollectionKey::~UsernamesCollectionKey() {}
16 bool UsernamesCollectionKey::operator<(
17 const UsernamesCollectionKey& other) const {
18 if (username != other.username)
19 return username < other.username;
20 if (password != other.password)
21 return password < other.password;
22 return realm < other.realm;
25 PasswordFormFillData::PasswordFormFillData() : wait_for_username(false) {
28 PasswordFormFillData::~PasswordFormFillData() {
31 void InitPasswordFormFillData(
32 const PasswordForm& form_on_page,
33 const PasswordFormMap& matches,
34 const PasswordForm* const preferred_match,
35 bool wait_for_username_before_autofill,
36 bool enable_other_possible_usernames,
37 PasswordFormFillData* result) {
38 // Note that many of the |FormFieldData| members are not initialized for
39 // |username_field| and |password_field| because they are currently not used
40 // by the password autocomplete code.
41 FormFieldData username_field;
42 username_field.name = form_on_page.username_element;
43 username_field.value = preferred_match->username_value;
44 FormFieldData password_field;
45 password_field.name = form_on_page.password_element;
46 password_field.value = preferred_match->password_value;
47 password_field.form_control_type = "password";
49 // Fill basic form data.
50 result->basic_data.name = form_on_page.form_data.name;
51 result->basic_data.origin = form_on_page.origin;
52 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;
57 result->preferred_realm = preferred_match->original_signon_realm;
59 // Copy additional username/value pairs.
60 PasswordFormMap::const_iterator iter;
61 for (iter = matches.begin(); iter != matches.end(); iter++) {
62 if (iter->second != preferred_match) {
63 PasswordAndRealm value;
64 value.password = iter->second->password_value;
65 value.realm = iter->second->original_signon_realm;
66 result->additional_logins[iter->first] = value;
68 if (enable_other_possible_usernames &&
69 !iter->second->other_possible_usernames.empty()) {
70 // Note that there may be overlap between other_possible_usernames and
71 // 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
73 // want to revisit this in the future.
74 UsernamesCollectionKey key;
75 key.username = iter->first;
76 key.password = iter->second->password_value;
77 key.realm = iter->second->original_signon_realm;
78 result->other_possible_usernames[key] =
79 iter->second->other_possible_usernames;
84 } // namespace autofill