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 #ifndef COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_FILL_DATA_H_
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_FILL_DATA_H_
10 #include "base/memory/scoped_ptr.h"
11 #include "components/autofill/core/common/form_data.h"
12 #include "components/autofill/core/common/password_form.h"
16 // Helper struct for PasswordFormFillData
17 struct UsernamesCollectionKey {
18 UsernamesCollectionKey();
19 ~UsernamesCollectionKey();
21 // Defined so that this struct can be used as a key in a std::map.
22 bool operator<(const UsernamesCollectionKey& other) const;
24 base::string16 username;
25 base::string16 password;
29 struct PasswordAndRealm {
30 base::string16 password;
34 // Structure used for autofilling password forms. Note that the realms in this
35 // struct are only set when the password's realm differs from the realm of the
36 // form that we are filling.
37 struct PasswordFormFillData {
38 typedef std::map<base::string16, PasswordAndRealm> LoginCollection;
39 typedef std::map<UsernamesCollectionKey,
40 std::vector<base::string16> > UsernamesCollection;
42 // Identifies the HTML form on the page and preferred username/password for
46 // The signon realm of the preferred user/pass pair.
47 std::string preferred_realm;
49 // A list of other matching username->PasswordAndRealm pairs for the form.
50 LoginCollection additional_logins;
52 // A list of possible usernames in the case where we aren't completely sure
53 // that the original saved username is correct. This data is keyed by the
54 // saved username/password to ensure uniqueness, though the username is not
56 UsernamesCollection other_possible_usernames;
58 // Tells us whether we need to wait for the user to enter a valid username
59 // before we autofill the password. By default, this is off unless the
60 // PasswordManager determined there is an additional risk associated with this
61 // form. This can happen, for example, if action URI's of the observed form
62 // and our saved representation don't match up.
63 bool wait_for_username;
65 PasswordFormFillData();
66 ~PasswordFormFillData();
69 // Create a FillData structure in preparation for autofilling a form,
70 // from basic_data identifying which form to fill, and a collection of
71 // matching stored logins to use as username/password values.
72 // |preferred_match| should equal (address) one of matches.
73 // |wait_for_username_before_autofill| is true if we should not autofill
74 // anything until the user typed in a valid username and blurred the field.
75 // If |enable_possible_usernames| is true, we will populate possible_usernames
77 void InitPasswordFormFillData(
78 const PasswordForm& form_on_page,
79 const PasswordFormMap& matches,
80 const PasswordForm* const preferred_match,
81 bool wait_for_username_before_autofill,
82 bool enable_other_possible_usernames,
83 PasswordFormFillData* result);
85 } // namespace autofill
87 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_FILL_DATA_H__