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