Upstream version 10.39.225.0
[platform/framework/web/crosswalk.git] / src / components / autofill / core / common / password_form.h
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_H__
6 #define COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_H__
7
8 #include <map>
9 #include <string>
10 #include <vector>
11
12 #include "base/time/time.h"
13 #include "components/autofill/core/common/form_data.h"
14 #include "url/gurl.h"
15
16 namespace autofill {
17
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.
20 //
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.
25 //
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
34 // representation.
35 //
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.
39
40 struct PasswordForm {
41   // Enum to differentiate between HTML form based authentication, and dialogs
42   // using basic or digest schemes. Default is SCHEME_HTML. Only PasswordForms
43   // of the same Scheme will be matched/autofilled against each other.
44   enum Scheme {
45     SCHEME_HTML,
46     SCHEME_BASIC,
47     SCHEME_DIGEST,
48     SCHEME_OTHER,
49     SCHEME_LAST = SCHEME_OTHER
50   } scheme;
51
52   // The "Realm" for the sign-on (scheme, host, port for SCHEME_HTML, and
53   // contains the HTTP realm for dialog-based forms).
54   // The signon_realm is effectively the primary key used for retrieving
55   // data from the database, so it must not be empty.
56   std::string signon_realm;
57
58   // The original "Realm" for the sign-on (scheme, host, port for SCHEME_HTML,
59   // and contains the HTTP realm for dialog-based forms). This realm is only set
60   // when two PasswordForms are matched when trying to find a login/pass pair
61   // for a site. It is only set to a non-empty value during a match of the
62   // original stored login/pass and the current observed form if all these
63   // statements are true:
64   // 1) The full signon_realm is not the same.
65   // 2) The registry controlled domain is the same. For example; example.com,
66   // m.example.com, foo.login.example.com and www.example.com would all resolve
67   // to example.com since .com is the public suffix.
68   // 3) The scheme is the same.
69   // 4) The port is the same.
70   // For example, if there exists a stored password for http://www.example.com
71   // (where .com is the public suffix) and the observed form is
72   // http://m.example.com, |original_signon_realm| must be set to
73   // http://www.example.com.
74   std::string original_signon_realm;
75
76   // The URL (minus query parameters) containing the form. This is the primary
77   // data used by the PasswordManager to decide (in longest matching prefix
78   // fashion) whether or not a given PasswordForm result from the database is a
79   // good fit for a particular form on a page, so it must not be empty.
80   GURL origin;
81
82   // The action target of the form. This is the primary data used by the
83   // PasswordManager for form autofill; that is, the action of the saved
84   // credentials must match the action of the form on the page to be autofilled.
85   // If this is empty / not available, it will result in a "restricted"
86   // IE-like autofill policy, where we wait for the user to type in his
87   // username before autofilling the password. In these cases, after successful
88   // login the action URL will automatically be assigned by the
89   // PasswordManager.
90   //
91   // When parsing an HTML form, this must always be set.
92   GURL action;
93
94   // The name of the submit button used. Optional; only used in scoring
95   // of PasswordForm results from the database to make matches as tight as
96   // possible.
97   //
98   // When parsing an HTML form, this must always be set.
99   base::string16 submit_element;
100
101   // The name of the username input element. Optional (improves scoring).
102   //
103   // When parsing an HTML form, this must always be set.
104   base::string16 username_element;
105
106   // The username. Optional.
107   //
108   // When parsing an HTML form, this is typically empty unless the site
109   // has implemented some form of autofill.
110   base::string16 username_value;
111
112   // This member is populated in cases where we there are multiple input
113   // elements that could possibly be the username. Used when our heuristics for
114   // determining the username are incorrect. Optional.
115   //
116   // When parsing an HTML form, this is typically empty.
117   std::vector<base::string16> other_possible_usernames;
118
119   // The name of the input element corresponding to the current password.
120   // Optional (improves scoring).
121   //
122   // When parsing an HTML form, this will always be set, unless it is a sign-up
123   // form or a change password form that does not ask for the current password.
124   // In these two cases the |new_password_element| will always be set.
125   base::string16 password_element;
126
127   // The current password. Must be non-empty for PasswordForm instances that are
128   // meant to be persisted to the password store.
129   //
130   // When parsing an HTML form, this is typically empty.
131   base::string16 password_value;
132
133   // False if autocomplete is set to "off" for the password input element;
134   // True otherwise.
135   bool password_autocomplete_set;
136
137   // If the form was a sign-up or a change password form, the name of the input
138   // element corresponding to the new password. Optional, and not persisted.
139   base::string16 new_password_element;
140
141   // The new password. Optional, and not persisted.
142   base::string16 new_password_value;
143
144   // Whether or not this login was saved under an HTTPS session with a valid
145   // SSL cert. We will never match or autofill a PasswordForm where
146   // ssl_valid == true with a PasswordForm where ssl_valid == false. This means
147   // passwords saved under HTTPS will never get autofilled onto an HTTP page.
148   // When importing, this should be set to true if the page URL is HTTPS, thus
149   // giving it "the benefit of the doubt" that the SSL cert was valid when it
150   // was saved. Default to false.
151   bool ssl_valid;
152
153   // True if this PasswordForm represents the last username/password login the
154   // user selected to log in to the site. If there is only one saved entry for
155   // the site, this will always be true, but when there are multiple entries
156   // the PasswordManager ensures that only one of them has a preferred bit set
157   // to true. Default to false.
158   //
159   // When parsing an HTML form, this is not used.
160   bool preferred;
161
162   // When the login was saved (by chrome).
163   //
164   // When parsing an HTML form, this is not used.
165   base::Time date_created;
166
167   // When the login was downloaded from the sync server. For local passwords is
168   // not used.
169   //
170   // When parsing an HTML form, this is not used.
171   base::Time date_synced;
172
173   // Tracks if the user opted to never remember passwords for this form. Default
174   // to false.
175   //
176   // When parsing an HTML form, this is not used.
177   bool blacklisted_by_user;
178
179   // Enum to differentiate between manually filled forms and forms with auto
180   // generated passwords.
181   enum Type {
182     TYPE_MANUAL,
183     TYPE_GENERATED,
184     TYPE_LAST = TYPE_GENERATED
185   };
186
187   // The form type. Not used yet. Please see http://crbug.com/152422
188   Type type;
189
190   // The number of times that this username/password has been used to
191   // authenticate the user.
192   //
193   // When parsing an HTML form, this is not used.
194   int times_used;
195
196   // True if additional system level authentication should be used
197   // (if available) before using this password for autofill.
198   //
199   // Default to false.
200   bool use_additional_authentication;
201
202   // Autofill representation of this form. Used to communicate with the
203   // Autofill servers if necessary. Currently this is only used to help
204   // determine forms where we can trigger password generation.
205   //
206   // When parsing an HTML form, this is normally set.
207   FormData form_data;
208
209   // These following fields are set by a website using the Credential Manager
210   // API. They will be empty and remain unused for sites which do not use that
211   // API.
212   //
213   // User friendly name to show in the UI.
214   base::string16 display_name;
215
216   // The URL of the user's avatar to display in the UI.
217   GURL avatar_url;
218
219   // The URL of identity provider used for federated login.
220   GURL federation_url;
221
222   // If true, Chrome will sign the user in automatically using the credentials.
223   // This field isn't synced deliberately.
224   bool is_zero_click;
225
226   // Returns true if this match was found using public suffix matching.
227   bool IsPublicSuffixMatch() const;
228
229   // Equality operators for testing.
230   bool operator==(const PasswordForm& form) const;
231   bool operator!=(const PasswordForm& form) const;
232
233   PasswordForm();
234   ~PasswordForm();
235 };
236
237 // Map username to PasswordForm* for convenience. See password_form_manager.h.
238 typedef std::map<base::string16, PasswordForm*> PasswordFormMap;
239
240 typedef std::map<base::string16, const PasswordForm*> ConstPasswordFormMap;
241
242 // For testing.
243 std::ostream& operator<<(std::ostream& os,
244                          const autofill::PasswordForm& form);
245
246 }  // namespace autofill
247
248 #endif  // COMPONENTS_AUTOFILL_CORE_COMMON_PASSWORD_FORM_H__