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_H__
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_H__
12 #include "base/time/time.h"
13 #include "components/autofill/core/common/form_data.h"
18 // The PasswordForm struct encapsulates information about a login form,
19 // which can be an HTML form or a dialog with username/password text fields.
21 // The Web Data database stores saved username/passwords and associated form
22 // metdata using a PasswordForm struct, typically one that was created from
23 // a parsed HTMLFormElement or LoginDialog, but the saved entries could have
24 // also been created by imported data from another browser.
26 // The PasswordManager implements a fuzzy-matching algorithm to compare saved
27 // PasswordForm entries against PasswordForms that were created from a parsed
28 // HTML or dialog form. As one might expect, the more data contained in one
29 // of the saved PasswordForms, the better the job the PasswordManager can do
30 // in matching it against the actual form it was saved on, and autofill
31 // accurately. But it is not always possible, especially when importing from
32 // other browsers with different data models, to copy over all the information
33 // about a particular "saved password entry" to our PasswordForm
36 // The field descriptions in the struct specification below are intended to
37 // describe which fields are not strictly required when adding a saved password
38 // entry to the database and how they can affect the matching process.
41 // Enum to keep track of what information has been sent to the server about
42 // this form regarding password generation.
43 enum GenerationUploadStatus
{
47 // Reserve a few values for future use.
51 // Enum to differentiate between HTML form based authentication, and dialogs
52 // using basic or digest schemes. Default is SCHEME_HTML. Only PasswordForms
53 // of the same Scheme will be matched/autofilled against each other.
59 SCHEME_LAST
= SCHEME_OTHER
62 // During form parsing, Chrome tries to partly understand the type of the form
63 // based on the layout of its fields. The result of this analysis helps to
64 // treat the form correctly once the low-level information is lost by
65 // converting the web form into a PasswordForm. It is only used for observed
66 // HTML forms, not for stored credentials.
68 // Forms which either do not need to be classified, or cannot be classified
71 // Login and signup forms combined in one <form>, to distinguish them from,
72 // e.g., change-password forms.
73 LAYOUT_LOGIN_AND_SIGNUP
,
74 LAYOUT_LAST
= LAYOUT_LOGIN_AND_SIGNUP
77 // The "Realm" for the sign-on. This is scheme, host, port for SCHEME_HTML.
78 // Dialog based forms also contain the HTTP realm. Android based forms will
79 // contain a string of the form "android://<hash of cert>@<package name>"
81 // The signon_realm is effectively the primary key used for retrieving
82 // data from the database, so it must not be empty.
83 std::string signon_realm
;
85 // The original "Realm" for the sign-on (scheme, host, port for SCHEME_HTML,
86 // and contains the HTTP realm for dialog-based forms). This realm is only set
87 // when two PasswordForms are matched when trying to find a login/pass pair
88 // for a site. It is only set to a non-empty value during a match of the
89 // original stored login/pass and the current observed form if all these
90 // statements are true:
91 // 1) The full signon_realm is not the same.
92 // 2) The registry controlled domain is the same. For example; example.com,
93 // m.example.com, foo.login.example.com and www.example.com would all resolve
94 // to example.com since .com is the public suffix.
95 // 3) The scheme is the same.
96 // 4) The port is the same.
97 // For example, if there exists a stored password for http://www.example.com
98 // (where .com is the public suffix) and the observed form is
99 // http://m.example.com, |original_signon_realm| must be set to
100 // http://www.example.com.
101 std::string original_signon_realm
;
103 // An origin URL consists of the scheme, host, port and path; the rest is
104 // stripped. This is the primary data used by the PasswordManager to decide
105 // (in longest matching prefix fashion) whether or not a given PasswordForm
106 // result from the database is a good fit for a particular form on a page.
107 // This should not be empty except for Android based credentials.
108 // TODO(melandory): origin should be renamed in order to be consistent with
109 // GURL definition of origin.
112 // The action target of the form; like |origin| URL consists of the scheme,
113 // host, port and path; the rest is stripped. This is the primary data used by
114 // the PasswordManager for form autofill; that is, the action of the saved
115 // credentials must match the action of the form on the page to be autofilled.
116 // If this is empty / not available, it will result in a "restricted" IE-like
117 // autofill policy, where we wait for the user to type in his username before
118 // autofilling the password. In these cases, after successful login the action
119 // URL will automatically be assigned by the PasswordManager.
121 // When parsing an HTML form, this must always be set.
124 // The name of the submit button used. Optional; only used in scoring
125 // of PasswordForm results from the database to make matches as tight as
128 // When parsing an HTML form, this must always be set.
129 base::string16 submit_element
;
131 // The name of the username input element. Optional (improves scoring).
133 // When parsing an HTML form, this must always be set.
134 base::string16 username_element
;
136 // Whether the |username_element| has an autocomplete=username attribute. This
137 // is only used in parsed HTML forms.
138 bool username_marked_by_site
;
140 // The username. Optional.
142 // When parsing an HTML form, this is typically empty unless the site
143 // has implemented some form of autofill.
144 base::string16 username_value
;
146 // This member is populated in cases where we there are multiple input
147 // elements that could possibly be the username. Used when our heuristics for
148 // determining the username are incorrect. Optional.
150 // When parsing an HTML form, this is typically empty.
151 std::vector
<base::string16
> other_possible_usernames
;
153 // The name of the input element corresponding to the current password.
154 // Optional (improves scoring).
156 // When parsing an HTML form, this will always be set, unless it is a sign-up
157 // form or a change password form that does not ask for the current password.
158 // In these two cases the |new_password_element| will always be set.
159 base::string16 password_element
;
161 // The current password. Must be non-empty for PasswordForm instances that are
162 // meant to be persisted to the password store.
164 // When parsing an HTML form, this is typically empty.
165 base::string16 password_value
;
167 // False if autocomplete is set to "off" for the password input element;
169 bool password_autocomplete_set
;
171 // If the form was a sign-up or a change password form, the name of the input
172 // element corresponding to the new password. Optional, and not persisted.
173 base::string16 new_password_element
;
175 // The new password. Optional, and not persisted.
176 base::string16 new_password_value
;
178 // Whether the |new_password_element| has an autocomplete=new-password
179 // attribute. This is only used in parsed HTML forms.
180 bool new_password_marked_by_site
;
182 // Whether or not this login was saved under an HTTPS session with a valid
183 // SSL cert. We will never match or autofill a PasswordForm where
184 // ssl_valid == true with a PasswordForm where ssl_valid == false. This means
185 // passwords saved under HTTPS will never get autofilled onto an HTTP page.
186 // When importing, this should be set to true if the page URL is HTTPS, thus
187 // giving it "the benefit of the doubt" that the SSL cert was valid when it
188 // was saved. Default to false.
191 // True if this PasswordForm represents the last username/password login the
192 // user selected to log in to the site. If there is only one saved entry for
193 // the site, this will always be true, but when there are multiple entries
194 // the PasswordManager ensures that only one of them has a preferred bit set
195 // to true. Default to false.
197 // When parsing an HTML form, this is not used.
200 // When the login was saved (by chrome).
202 // When parsing an HTML form, this is not used.
203 base::Time date_created
;
205 // When the login was downloaded from the sync server. For local passwords is
208 // When parsing an HTML form, this is not used.
209 base::Time date_synced
;
211 // Tracks if the user opted to never remember passwords for this form. Default
214 // When parsing an HTML form, this is not used.
215 bool blacklisted_by_user
;
217 // Enum to differentiate between manually filled forms and forms with auto
218 // generated passwords.
222 TYPE_LAST
= TYPE_GENERATED
228 // The number of times that this username/password has been used to
229 // authenticate the user.
231 // When parsing an HTML form, this is not used.
234 // Autofill representation of this form. Used to communicate with the
235 // Autofill servers if necessary. Currently this is only used to help
236 // determine forms where we can trigger password generation.
238 // When parsing an HTML form, this is normally set.
241 // What information has been sent to the Autofill server about this form.
242 GenerationUploadStatus generation_upload_status
;
244 // These following fields are set by a website using the Credential Manager
245 // API. They will be empty and remain unused for sites which do not use that
248 // User friendly name to show in the UI.
249 base::string16 display_name
;
251 // The URL of the user's avatar to display in the UI.
254 // The URL of identity provider used for federated login.
257 // If true, Chrome will not return this credential to a site in response to
258 // 'navigator.credentials.request()' without user interaction.
259 // Once user selects this credential the flag is reseted.
260 bool skip_zero_click
;
262 // The layout as determined during parsing. Default value is LAYOUT_OTHER.
265 // If true, this form was parsed using Autofill predictions.
266 bool was_parsed_using_autofill_predictions
;
268 // TODO(vabr): Remove |is_alive| once http://crbug.com/486931 is fixed.
269 bool is_alive
; // Set on construction, reset on destruction.
271 // Returns true if this match was found using public suffix matching.
272 bool IsPublicSuffixMatch() const;
274 // Equality operators for testing.
275 bool operator==(const PasswordForm
& form
) const;
276 bool operator!=(const PasswordForm
& form
) const;
282 // Map username to PasswordForm* for convenience. See password_form_manager.h.
283 typedef std::map
<base::string16
, PasswordForm
*> PasswordFormMap
;
285 typedef std::map
<base::string16
, const PasswordForm
*> ConstPasswordFormMap
;
288 std::ostream
& operator<<(std::ostream
& os
, PasswordForm::Layout layout
);
289 std::ostream
& operator<<(std::ostream
& os
, const autofill::PasswordForm
& form
);
290 std::ostream
& operator<<(std::ostream
& os
, autofill::PasswordForm
* form
);
292 } // namespace autofill
294 #endif // COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_H__